Re: Trigger before delete does fire before, but delete doesn't not happen

From: Adrian Klaver <aklaver(at)comcast(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Stéphane A(dot) Schildknecht <stephane(dot)schildknecht(at)postgresqlfr(dot)org>, pgsql-general(at)postgresql(dot)org
Subject: Re: Trigger before delete does fire before, but delete doesn't not happen
Date: 2008-12-01 20:32:07
Message-ID: 779447495.987121228163527348.JavaMail.root@sz0030a.emeryville.ca.mail.comcast.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

----- "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:

> Adrian Klaver <aklaver(at)comcast(dot)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.
>

Thanks for the explanation. Just so I am clear,the act of updating the row in p_commandeligne_ad creates a new tuple for the row with id of 1. This means the original statement "delete from commande where id=1" runs against a version of the row that no longer exists and becomes a no-op statement. This happens because the trigger was run as BEFORE and changed the row from under the original statement.

> regards, tom lane

Adrian Klaver
aklaver(at)comcast(dot)net

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Maxim Boguk 2008-12-01 20:32:14 Re: Indexes on NULL's and order by ... limit N queries
Previous Message Scott Marlowe 2008-12-01 20:31:26 Re: Monty on MySQL 5.1: "Oops, we did it again"