Re: Before/After trigger sequencing questiont

From: Mike Nolan <nolan(at)gw(dot)tssi(dot)com>
To: tgl(at)sss(dot)pgh(dot)pa(dot)us (Tom Lane)
Cc: pgsql-general(at)postgresql(dot)org (pgsql general list)
Subject: Re: Before/After trigger sequencing questiont
Date: 2004-07-28 07:32:19
Message-ID: 200407280732.i6S7WKbM004075@gw.tssi.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> Mike Nolan <nolan(at)gw(dot)tssi(dot)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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Marius Andreiana 2004-07-28 07:55:16 Re: Data model for Postfix v2
Previous Message Scott Marlowe 2004-07-28 04:37:17 Re: altering a table to set serial function