Altering field passed as parameter to plpgsql trigger

From: Steve Crawford <scrawford(at)pinpointresearch(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Altering field passed as parameter to plpgsql trigger
Date: 2007-12-12 19:20:41
Message-ID: 47603489.9040207@pinpointresearch.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I am trying to make a function that can be reused as a trigger on
various tables but am somehow not finding the correct syntax for using a
parameter to the function to identify the column to be altered by the
trigger. Stripped to basics:

create or replace function foo_trigger()
returns trigger
as '
declare
...
begin
trigger_table = TG_ARGV[0];
field_to_alter = TG_ARGV[1];
...
new.field_to_alter = some_computed_value; <<==========
return new;
end;'
language 'plpgsql';

create trigger foo_change before insert on foo
for each row execute procedure foo_trigger('foo','somealteredfield');

What is the correct syntax for the line:
new.field_to_alter = some_computed_value;

Also, does plpgsql have a preferred way to identify the table that fired
the trigger. I see the syntax for C but not for plpgsql.

Cheers,
Steve

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Ivan Sergio Borgonovo 2007-12-12 19:40:13 why chose pgsql for "light" CMS was: General Q's
Previous Message Anu Padki 2007-12-12 19:09:46 jdbc lob and postgresql