Re: BUG #1274: Trigger sequence incorrect

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: shancheng <sd_shancheng(at)hotmail(dot)com>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #1274: Trigger sequence incorrect
Date: 2004-10-01 06:23:25
Message-ID: 20041001062325.GA8787@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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/

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Alexander Zhiltsov 2004-10-01 08:46:33 Bug in PostrgeSQL 8.0beta
Previous Message Tom Lane 2004-10-01 05:14:18 Re: PLPGSQL and FOUND stange behaviour after EXECUTE