From: Dirk Heinrichs <dirk.heinrichs@online.de>
To: pgsql-interfaces@postgresql.org
Subject: plPerl: How to iterate over $_TD->{new} in a trigger function?
Date: Wed, 28 Jun 2006 20:00:36 +0200
Message-ID: <200606282000.43782.dirk.heinrichs@online.de> (raw)
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-interfaces@postgresql.org
Cc: dirk.heinrichs@online.de
Subject: Re: plPerl: How to iterate over $_TD->{new} in a trigger function?
In-Reply-To: <200606282000.43782.dirk.heinrichs@online.de>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox