pg.ddx.io pgsql-interfaces@postgresql.org mailing list archive
help / color / mirror / Atom feedplPerl: How to iterate over $_TD->{new} in a trigger function?
2+ messages / 1 participants
[nested] [flat]
* plPerl: How to iterate over $_TD->{new} in a trigger function?
@ 2006-06-28 18:00 Dirk Heinrichs <dirk.heinrichs@online.de>
0 siblings, 1 reply; 2+ messages in thread
From: Dirk Heinrichs @ 2006-06-28 18:00 UTC (permalink / raw)
To: pgsql-interfaces
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
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: plPerl: How to iterate over $_TD->{new} in a trigger function?
@ 2006-06-28 18:15 Dirk Heinrichs <dirk.heinrichs@online.de>
parent: Dirk Heinrichs <dirk.heinrichs@online.de>
0 siblings, 0 replies; 2+ messages in thread
From: Dirk Heinrichs @ 2006-06-28 18:15 UTC (permalink / raw)
To: pgsql-interfaces
Am Mittwoch, 28. Juni 2006 20:00 schrieb Dirk Heinrichs:
> 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}.
OK, got it myself.
> create or replace function test_trig() returns trigger as $$
> elog (INFO, "Table is: $_TD->{relname}\n");
> my %newrow = %_TD->{new};
my %newrow = %{$_TD->{new}};
> elog (INFO, "$x=$y\n") while (($x,$y) = each %newrow);
> return;
> $$ language plperl;
Works as expected.
Bye...
Dirk
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2006-06-28 18:15 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2006-06-28 18:00 plPerl: How to iterate over $_TD->{new} in a trigger function? Dirk Heinrichs <dirk.heinrichs@online.de>
2006-06-28 18:15 ` Dirk Heinrichs <dirk.heinrichs@online.de>
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