public inbox for [email protected]  
help / color / mirror / Atom feed
From: Michael Fuhr <[email protected]>
To: James Cloos <[email protected]>
Cc: [email protected]
Subject: Re: plperl and triggers
Date: Mon, 11 Sep 2006 09:44:34 -0600
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>

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



view thread (3+ messages)  latest in thread

reply

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: [email protected]
  Cc: [email protected], [email protected]
  Subject: Re: plperl and triggers
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox