Re: Delete triggers order in delete cascade (pg 8.3.7). - Mailing list pgsql-general

From Richard Huxton
Subject Re: Delete triggers order in delete cascade (pg 8.3.7).
Date
Msg-id 4A4CA49D.8000600@archonet.com
Whole thread Raw
In response to Delete triggers order in delete cascade (pg 8.3.7).  (Michaël Lemaire <adminsys@rodacom.fr>)
Responses Re: Delete triggers order in delete cascade (pg 8.3.7).
List pgsql-general
Michaël Lemaire wrote:
> Hi all.
>
> I've come across a problem with delete cascade.
>
> I have three tables A, B and C.
> Table B has a foreign key on A with delete cascade.
> Table C has a foreign key on B with delete cascade.
> So, we have this reference chain: C->B->A
> All three tables have an 'on delete' trigger.
>
> My problem is, when I delete a row from A, the delete triggers are
> fired in the order A then B then C, which is the opposite of what I
> expected (the row from B should be deleted before the A one, or the
> reference constraint would break).

The "on delete cascade" are (sort of) implemented with system triggers.
So deleting a row from A triggers a delete on B where fkey=X and so on.

> This happens with 'after' and 'before' triggers.
> I really need the order to be C then B then A.

Why? What are you trying to do?

--
   Richard Huxton
   Archonet Ltd

pgsql-general by date:

Previous
From: Greg Stark
Date:
Subject: Re: 1 Sequence per Row i.e. each customer's first order starts at 1
Next
From: Reid Thompson
Date:
Subject: Re: Does anyone know of a job scheduler that uses PostgreSQL?