Re: Trigger before delete does fire before, but delete doesn't not happen - Mailing list pgsql-general

From Tom Lane
Subject Re: Trigger before delete does fire before, but delete doesn't not happen
Date
Msg-id 24220.1228157636@sss.pgh.pa.us
Whole thread Raw
In response to Re: Trigger before delete does fire before, but delete doesn't not happen  (Adrian Klaver <aklaver@comcast.net>)
List pgsql-general
Adrian Klaver <aklaver@comcast.net> writes:
> The problem as far as I can tell is tuple visibility.

Sort of: the triggers on commandeligne fire (and update the commande row)
at completion of the DELETE command inside p_commande_bd.  This means
that by the time control returns from that trigger, the tuple version
that was targeted for deletion is already dead, so there's nothing to
do.  It doesn't chain up to the newer version of the row.

An AFTER trigger would be better for this on general principles, anyway.
The rule of thumb is "use a BEFORE trigger to adjust what happens to the
target row, but use an AFTER trigger to propagate the changes to other
rows".  If you don't do it that way then you have problems whenever
there are multiple triggers, since no individual BEFORE trigger can be
sure it knows the final state of the row.

            regards, tom lane

pgsql-general by date:

Previous
From: "Malinka Rellikwodahs"
Date:
Subject: Re: db backup script in gentoo
Next
From: Alvaro Herrera
Date:
Subject: Re: Detecting changes to certain fields in 'before update' trigger functions