Thread: plperl and triggers
The manual says that $_TD->{old} contains the old value of the row being operated on in a trigger, and $_TD->{new} the new value to be used istead. When using plpgsql I find that the equivs OLD and NEW do work that way, but with plperlu there was only $_TD->{new}. Perhaps {old} is only set on an update. Or on an AFTER trigger to an insert? Or perhaps {old} only gets set if {new} is altered? Whatever the reality, the doc should be fixed to explain exactly when {old} and {new} exist and their semantics. Liberal use of, eg, elog(WARNING, Dumper(\$_TD)) made it easy to get my trigger function working as desired, but it would be cool to document the details.... (In general, the docs are great. I do sometimes have to read a given section more than once -- or thrice -- to get it, but that is as much due to fatigue as anything. And I am one of those who tend to learn new stuff better when reading from paper than from emitive displays like lcds or crts, for whatever reason.) (Or maybe I'm just getting old. ;-) -JimC -- James Cloos <cloos@jhcloos.com> OpenPGP: 0xED7DAEA6
On Sun, Sep 10, 2006 at 11:41:38PM -0400, James Cloos wrote: > The manual says that $_TD->{old} contains the old value of the row > being operated on in a trigger, and $_TD->{new} the new value to be > used istead. > > When using plpgsql I find that the equivs OLD and NEW do work that > way, but with plperlu there was only $_TD->{new}. Are you sure the tests were identical other than the trigger function language? Based on your description I'd guess that you did an UPDATE with PL/pgSQL and an INSERT with PL/PerlU. > Perhaps {old} is only set on an update. Or on an AFTER trigger to > an insert? > > Or perhaps {old} only gets set if {new} is altered? New and/or old rows are available in row-level BEFORE and AFTER triggers. New rows are available in INSERT and UPDATE triggers; old rows are available in UPDATE and DELETE triggers. This behavior should be the same in all languages; if you have an example that shows otherwise then please post it. > Whatever the reality, the doc should be fixed to explain exactly > when {old} and {new} exist and their semantics. "A patch would be welcome" :-) The PL/Perl documentation doesn't describe the semantics but the "Triggers" chapter does. If you've found a discrepancy between documentation and behavior then please post a self-contained test case. -- Michael Fuhr
>>>>> "Michael" == Michael Fuhr <mike@fuhr.org> writes: Michael> Are you sure the tests were identical other than the trigger Michael> function language? Based on your description I'd guess that Michael> you did an UPDATE with PL/pgSQL and an INSERT with PL/PerlU. I was sure when I wrote that, but -- most embarrassingly -- I've not been able to reproduce.... In the exhausted euphoria of finishing a project I clearly [SIGH] misremembered the steps along the way. Apologies for the false alarm. -JimC