Re: BUG #1274: Trigger sequence incorrect - Mailing list pgsql-bugs

From Michael Fuhr
Subject Re: BUG #1274: Trigger sequence incorrect
Date
Msg-id 20041001062325.GA8787@winnie.fuhr.org
Whole thread Raw
In response to BUG #1274: Trigger sequence incorrect  ("PostgreSQL Bugs List" <pgsql-bugs@postgresql.org>)
List pgsql-bugs
On Thu, Sep 30, 2004 at 07:06:10AM +0100, PostgreSQL Bugs List wrote:
>
> The problem happens when I was trying the example that is described in
> "PostgreSQL 8.0.0beta1 Documentation, chapt 33.4 --- A Complete Example".
>
> At the last step, as the document says, the result should be:
> => DELETE FROM ttest;
> INFO:  trigf (fired before): there are 2 rows in ttest
> INFO:  trigf (fired after ): there are 1 rows in ttest
> INFO:  trigf (fired before): there are 1 rows in ttest
> INFO:  trigf (fired after ): there are 0 rows in ttest
> DELETE 2
>
> But what i see is that:
> test=# DELETE FROM ttest;
> NOTICE:  trigf (fired before): there are 2 tuples in ttest
> NOTICE:  trigf (fired before): there are 1 tuples in ttest
> NOTICE:  trigf (fired after ): there are 0 tuples in ttest
> NOTICE:  trigf (fired after ): there are 0 tuples in ttest
> DELETE 2
>
> The execution sequence of the triggers is incorrect.

Perhaps the execution sequence is correct and the documentation is
wrong.  Chapter 33.2 "Visibility of Data Changes" says this:

  When a row-level after trigger is fired, all data changes made
  by the outer command are already complete, and are visible to the
  invoked trigger function.

I interpret that to mean that all records will have been deleted
by the time any AFTER triggers are fired, which is the behavior
you're seeing.

Incidentally, 7.4.5 behaves the same way.  Maybe this behavior
change sometime after the example was written and the documentation
was never updated.

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

pgsql-bugs by date:

Previous
From: Tom Lane
Date:
Subject: Re: PLPGSQL and FOUND stange behaviour after EXECUTE
Next
From: "Aleksey Fedorchenko"
Date:
Subject: Re: BUG #1266: Improper unique constraint / MVCCactivitieswithin