"Omkar Rath" <orath(at)cisco(dot)com> writes:
> Say there is a stored procedure i.e FUNCTION sp_foo(...) which has say,
> SQL commands (any of SELECT,INSERT,UPDATE,DELETE) in its body, say S1
> followed by S2 then S3.... Furthermore, execution of statement S2
> results in trigger functions getting invoked (that contain yet other SQL
> statements).
>
> By the time, the trigger functions execute (as a result of S2), S3 has
> already executed.
In existing PG releases, AFTER triggers are always fired at the
completion of the whole interactive command (ie, the outer SELECT that
called sp_foo).
There are changes in 8.0 to fire them at the end of the specific query
that triggered them, which I believe will do what you want.
regards, tom lane