Re: Before/After trigger sequencing questiont - Mailing list pgsql-general

From Mike Nolan
Subject Re: Before/After trigger sequencing questiont
Date
Msg-id 200407280732.i6S7WKbM004075@gw.tssi.com
Whole thread Raw
In response to Re: Before/After trigger sequencing question  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Before/After trigger sequencing questiont  (Pierre-Frédéric Caillaud<lists@boutiquenumerique.com>)
Re: Before/After trigger sequencing questiont  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
> Mike Nolan <nolan@gw.tssi.com> writes:
> > I have a before insert trigger that updates a value in another table.
>
> > It appears that I cannot depend upon that update having taken place
> > in an after insert trigger on the first table.  (The one with the insert.)
>
> This seems a tad improbable, not to say impossible.  Concrete example,
> please?

I can't reproduce it using a simple example, but here's the sequence
of events that happened this morning (on 7.4.1):

1.  A record was inserted into a table with about a million rows in it.
2.  This insert triggered a before insert procedure that updated several
    values in a second table, one with about 580,000 rows in it.
    (This was via several different update statements in the trigger
    function.)
3.  The 'after insert' trigger on the first table calls another procedure
    using plperlu which in turn executes an external PHP program that
    does a lookup on the 2nd table (using one of the updated values as
    a key) then sends some e-mail.  It didn't find the record with the
    updated value.

In thinking it through while typing typing this note, I think the problem
is that the external PHP program doesn't see record with the updated value
yet because the transaction hasn't been completed.
--
Mike Nolan

pgsql-general by date:

Previous
From: des@des.no (Dag-Erling Smørgrav)
Date:
Subject: tablename type?
Next
From: Marius Andreiana
Date:
Subject: Re: Data model for Postfix v2