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

From Tom Lane
Subject Re: Before/After trigger sequencing questiont
Date
Msg-id 21495.1091024044@sss.pgh.pa.us
Whole thread Raw
In response to Re: Before/After trigger sequencing questiont  (Mike Nolan <nolan@gw.tssi.com>)
Responses Re: Before/After trigger sequencing questiont  (Mike Nolan <nolan@gw.tssi.com>)
List pgsql-general
Mike Nolan <nolan@gw.tssi.com> writes:
> 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.

Yeah, that would be my interpretation: the after trigger runs just
before the transaction commits, and your external PHP program can't
see the results since they haven't been committed yet.  Your description
makes it sound like the trigger invokes the PHP code synchronously,
in which case it'd never work at all ... but if it's just asynchronously
sending a message to make the PHP code run a bit later, then it would
work almost all the time.

You might want to think about using LISTEN/NOTIFY somehow to trigger the
PHP run.  A listener is guaranteed not to get the notification until
(and unless) the sending transaction commits.

            regards, tom lane

pgsql-general by date:

Previous
From: Prabu Subroto
Date:
Subject: Re: altering a starting value of "serial" macro
Next
From: Mike Nolan
Date:
Subject: Re: Before/After trigger sequencing questiont