Re: writable cte triggers reverse order

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Миша Тюрин <tmihail(at)bk(dot)ru>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>, Sergey Burladyan <eshkinkot(at)gmail(dot)com>, Marko Kreen <markokr(at)gmail(dot)com>
Subject: Re: writable cte triggers reverse order
Date: 2015-06-18 14:01:46
Message-ID: 3443.1434636106@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

=?UTF-8?B?0JzQuNGI0LAg0KLRjtGA0LjQvQ==?= <tmihail(at)bk(dot)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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Peter Kroon 2015-06-18 14:16:34 valgrind
Previous Message David G. Johnston 2015-06-18 13:56:30 Re: PL/pgSQL: How to return two columns and multiple rows