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

Re: plperl and triggers

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: James Cloos <cloos(at)jhcloos(dot)com>
Cc: pgsql-docs(at)postgresql(dot)org
Subject: Re: plperl and triggers
Date: 2006-09-11 15:44:34
Message-ID: 20060911154434.GA306@winnie.fuhr.org (view raw or flat)
Thread:
Lists: pgsql-docs
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

In response to

Responses

pgsql-docs by date

Next:From: James CloosDate: 2006-09-14 22:07:24
Subject: Re: plperl and triggers
Previous:From: James CloosDate: 2006-09-11 03:41:38
Subject: plperl and triggers

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group