Re: triggers: dynamic references to fields in NEW and OLD? - Mailing list pgsql-general

From Vance Maverick
Subject Re: triggers: dynamic references to fields in NEW and OLD?
Date
Msg-id 000001c8b70d$56b3f030$0201000a@corp.pgp.com
Whole thread Raw
In response to Re: triggers: dynamic references to fields in NEW and OLD?  (Klint Gore <kgore4@une.edu.au>)
Responses Re: triggers: dynamic references to fields in NEW and OLD?  ("Kerri Reno" <kreno@yumaed.org>)
List pgsql-general
Thanks!  Your solution clearly works, but it requires the shared function to
enumerate all possible column names.  In my real case, there are 8-10
distinct names, so that's a bit ugly....but it works.

    Vance

-----Original Message-----
If you just need which table triggered the function then |TG_TABLE_NAME| may
be simpler than passing parameters.

Something like this will probably work for you (replace the raise notice
with whatever you have to do)

create or replace function atest() returns trigger as $$ declare
   avalue int;
   tblfld text;
begin
   tblfld := tg_argv[0];
   if tblfld = 'aa' then
      avalue := new.aa;
   else
      if tblfld = 'bb' then
          avalue := new.bb;
      end if;
   end if;
   raise notice '%',avalue;
   return new;
end;
$$ language plpgsql;

klint.

--
Klint Gore
Database Manager
Sheep CRC
A.G.B.U.
University of New England
Armidale NSW 2350

Ph: 02 6773 3789
Fax: 02 6773 3266
EMail: kgore4@une.edu.au



pgsql-general by date:

Previous
From: Gerald Quimpo
Date:
Subject: Re: psql proxy
Next
From: "samslists@gmail.com"
Date:
Subject: Setting up phppgadmin under https/ssl (Apache)