Re: How to defer ON DELETE CASCADE

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Arjen Nienhuis <a(dot)g(dot)nienhuis(at)gmail(dot)com>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: How to defer ON DELETE CASCADE
Date: 2010-09-01 17:02:19
Message-ID: 26947.1283360539@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Arjen Nienhuis <a(dot)g(dot)nienhuis(at)gmail(dot)com> writes:
> If I create a DEFERRED ON DELETE CASCADE constraint, it doesn't really work
> as I expected. I expected it to defer the deletion to the end of the
> transaction, but it dosn't.

Yeah, this is per SQL spec as far as we can tell. Constraint checks can
be deferred till end of transaction, but "referential actions" are not
deferrable. They always happen during the triggering statement. For
instance SQL99 describes the result of a cascade deletion as being that
the referencing row is "marked for deletion" immediately, and then

15) All rows that are marked for deletion are effectively deleted
at the end of the SQL-statement, prior to the checking of any
integrity constraints.

(see 11.8 <referential constraint definition> general rules)

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Richard Huxton 2010-09-01 20:13:55 Re: On-disk size of db increased after restore
Previous Message Joshua D. Drake 2010-09-01 16:23:28 Re: Problems with ODBC Driver