Skip site navigation (1) Skip section navigation (2)

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search for
  Advanced Search

plPerl: How to iterate over $_TD->{new} in a trigger function?



Hi,

I want to write a generic trigger function, which can be attached to any 
table, but it seems I'm to stupid :-) to get column/value pairs out of 
$_TD->{new} and $_TD->{old}.

Here is my sample code:

create or replace function test_trig() returns trigger as $$
        elog (INFO, "Table is: $_TD->{relname}\n");
        my %newrow = %_TD->{new};
        elog (INFO, "$x=$y\n") while (($x,$y) = each %newrow);
        return;
$$ language plperl;

CREATE trigger trig1 after update or insert or delete on test for each row 
execute procedure test_trig();

Table test can be anything. This is what I get when I insert something:

# insert into test (data) values ('foo');
INFO:  Table is: test

INFO:  =

INSERT 0 1

What I want to get at the second "INFO:" line is:

INFO: data=foo

Any hints?

Thanks...

	Dirk

Attachment: pgpB2I9T6gphd.pgp
Description: PGP signature



Home | Main Index | Thread Index

Privacy Policy | PostgreSQL Archives hosted by Command Prompt, Inc. | Designed by tinysofa
Copyright © 1996 – 2008 PostgreSQL Global Development Group