pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Louis-David Mitterrand <vindex+lists-pgsql-sql@apartia.org>
To: pgsql-sql@postgresql.org
Subject: dynmic column names inside trigger?
Date: Tue, 20 Nov 2007 17:12:58 +0100
Message-ID: <20071120161258.GA27106@apartia.fr> (raw)

Hi,

I've got this trigger to clean up text entered in web forms:

	CREATE or replace FUNCTION sanitize_text() RETURNS "trigger"
		AS $$
	declare
	begin
		if old.story is not null and new.story != old.story
		then
			new.story = translate(new.story, E'\x92\x96', '''-');
			new.story = regexp_replace(new.story, E'\x9c', 'oe', 'g');
			new.story = regexp_replace(new.story, E'\x85', '...', 'g');
		end if;
		return new;
	end;
	$$
		LANGUAGE plpgsql;


	CREATE TRIGGER sanitize_text_trig
		BEFORE INSERT or update ON story
		FOR EACH ROW
		EXECUTE PROCEDURE sanitize_text();


I'd like to use it on other tables an columns but how can the column 
name be dynamic inside the procedure. Passing the column name in the 
trigger declaration and using it as NEW.TG_ARGV[0] seems out of the 
question.

Is there another solution out there?

Thanks,



view thread (9+ messages)  latest in thread

Message-ID: <20071120161258.GA27106@apartia.fr>
Permalink:  ../20071120161258.GA27106@apartia.fr/
Also on:    postgresql.org/message-id/20071120161258.GA27106@apartia.fr

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: vindex+lists-pgsql-sql@apartia.org
  Subject: Re: dynmic column names inside trigger?
  In-Reply-To: <20071120161258.GA27106@apartia.fr>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox