Re: writable cte triggers reverse order - Mailing list pgsql-general

From Tom Lane
Subject Re: writable cte triggers reverse order
Date
Msg-id 3443.1434636106@sss.pgh.pa.us
Whole thread Raw
In response to writable cte triggers reverse order  (Миша Тюрин <tmihail@bk.ru>)
List pgsql-general
=?UTF-8?B?0JzQuNGI0LAg0KLRjtGA0LjQvQ==?= <tmihail@bk.ru> writes:
> for me case listed below looks like something goes wrong (at least very strange)
> ...
> see on order of events -- INSERTs come first before DELETEs!

The reason for this is that the AFTER INSERT trigger events are queued
within the INSERT statements executed by the test_trg_inh_func function,
and then executed at the completions of those INSERT statements.  On
the other hand, the AFTER DELETE trigger events are queued by the outer
WITH ... DELETE ... INSERT statement, so they fire at the completion
of that statement.

You could probably get the behavior you want if you make all the triggers
DEFERRED so that they all fire at end-of-transaction, rather than at end
of the statement that queued them.

            regards, tom lane


pgsql-general by date:

Previous
From: "David G. Johnston"
Date:
Subject: Re: PL/pgSQL: How to return two columns and multiple rows
Next
From: Peter Kroon
Date:
Subject: valgrind