dynmic column names inside trigger?

From: Louis-David Mitterrand <vindex+lists-pgsql-sql(at)apartia(dot)org>
To: pgsql-sql(at)postgresql(dot)org
Subject: dynmic column names inside trigger?
Date: 2007-11-20 16:12:58
Message-ID: 20071120161258.GA27106@apartia.fr
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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,

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2007-11-20 16:56:02 Re: dynmic column names inside trigger?
Previous Message Andreas Joseph Krogh 2007-11-20 10:21:07 Loading 8.2 data into 8.1