Thread: Multiple TRIGGERs and OLD versus NEW "records"

Multiple TRIGGERs and OLD versus NEW "records"

From
Jorge Godoy
Date:
Hi!


(Consider these UPDATE triggers)


I can't test this for now since I'm not with a test database handy for now,
but I was thinking on what happens to OLD and NEW when running multiple
triggers.

For example, for the first trigger OLD is the equivalent to the data that is
stored at the database already, NEW is the data I'm sending to the database.
If I change some column -- e.g. fill in some automatic calculated column or a
timestamp column --, when I run the second trigger will OLD be the data stored
at the database already or will it be affected by the NEW data returned from
the previous trigger?

I know that NEW propagates, but does OLD change?  I suppose not and I can't
confirm that now...  If anyone has the answer, sharing would be nice.  If I
don't get any answer, I'll test and post the results later. :-)



TIA,
--
Jorge Godoy      <jgodoy@gmail.com>

Re: Multiple TRIGGERs and OLD versus NEW "records"

From
Tom Lane
Date:
Jorge Godoy <jgodoy@gmail.com> writes:
> If I change some column -- e.g. fill in some automatic calculated column or a
> timestamp column --, when I run the second trigger will OLD be the data stored
> at the database already or will it be affected by the NEW data returned from
> the previous trigger?

OLD is the data actually in the database.  NEW is the currently proposed row.
So prior triggers can change what you see as NEW, but not OLD.

            regards, tom lane

Re: Multiple TRIGGERs and OLD versus NEW "records"

From
Jorge Godoy
Date:
Tom Lane <tgl@sss.pgh.pa.us> writes:

> Jorge Godoy <jgodoy@gmail.com> writes:
>> If I change some column -- e.g. fill in some automatic calculated column or a
>> timestamp column --, when I run the second trigger will OLD be the data stored
>> at the database already or will it be affected by the NEW data returned from
>> the previous trigger?
>
> OLD is the data actually in the database.  NEW is the currently proposed row.
> So prior triggers can change what you see as NEW, but not OLD.
>
>             regards, tom lane

Thanks, Tom.  It's like I supposed.  I was going to test it tonight when I get
to my office but you saved me from that :-)



--
Jorge Godoy      <jgodoy@gmail.com>