Iterate OLD/NEW columns in a trigger?

Started by Steve - DNDabout 21 years ago5 messagesgeneral
Jump to latest
#1Steve - DND
postgres@digitalnothing.com

Is there a way to iterate the columns contained on the OLD/NEW. I want to do
some work in a function in a trigger, but I want it to be generic. I don't
want to have to create a separate trigger for each table, since the work
performed in the trigger is essentially the same for all of them. I just
need to be able to dynamically find the columns associated with OLD/NEW to
make it work. I didn't see anything in the docs about this, anyone have a
solution?

Thanks,
Steve

#2Scott Marlowe
smarlowe@g2switchworks.com
In reply to: Steve - DND (#1)
Re: Iterate OLD/NEW columns in a trigger?

On Thu, 2005-04-07 at 14:35, Steve - DND wrote:

Is there a way to iterate the columns contained on the OLD/NEW. I want to do
some work in a function in a trigger, but I want it to be generic. I don't
want to have to create a separate trigger for each table, since the work
performed in the trigger is essentially the same for all of them. I just
need to be able to dynamically find the columns associated with OLD/NEW to
make it work. I didn't see anything in the docs about this, anyone have a
solution?

try pltcl, it's supposed to be pretty good at this.

#3Sean Davis
sdavis2@mail.nih.gov
In reply to: Scott Marlowe (#2)
Re: Iterate OLD/NEW columns in a trigger?

On Apr 7, 2005, at 3:44 PM, Scott Marlowe wrote:

On Thu, 2005-04-07 at 14:35, Steve - DND wrote:

Is there a way to iterate the columns contained on the OLD/NEW. I
want to do
some work in a function in a trigger, but I want it to be generic. I
don't
want to have to create a separate trigger for each table, since the
work
performed in the trigger is essentially the same for all of them. I
just
need to be able to dynamically find the columns associated with
OLD/NEW to
make it work. I didn't see anything in the docs about this, anyone
have a
solution?

try pltcl, it's supposed to be pretty good at this.

As is plperl and likely plpython, and maybe others.

Sean

#4Steve - DND
postgres@digitalnothing.com
In reply to: Sean Davis (#3)
Re: Iterate OLD/NEW columns in a trigger?

try pltcl, it's supposed to be pretty good at this.

As is plperl and likely plpython, and maybe others.

Does anyone have an example of this at work? I tried a few Google searches,
but couldn't get any results showing iterating over the columns of a record.

Thanks,
Steve

#5Richard Huxton
dev@archonet.com
In reply to: Steve - DND (#4)
Re: Iterate OLD/NEW columns in a trigger?

Steve - DND wrote:

try pltcl, it's supposed to be pretty good at this.

As is plperl and likely plpython, and maybe others.

Does anyone have an example of this at work? I tried a few Google searches,
but couldn't get any results showing iterating over the columns of a record.

Attached - example of tcl function that tracks changes to target tables.

--
Richard Huxton
Archonet Ltd

Attachments:

pg_tcl_func_example.txttext/plain; name=pg_tcl_func_example.txtDownload