Re: deferred cascade delete re-check at end of transaction?

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: Michael Adler <adler(at)glimpser(dot)org>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: deferred cascade delete re-check at end of transaction?
Date: 2002-10-14 17:20:02
Message-ID: 20021014095254.V70349-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


On Mon, 14 Oct 2002, Michael Adler wrote:

>
> I have written a test that demonstrates a behavior that surprises me.
>
> I store a foreign key with a deferable cascade-delete. While in a
> transaction, I delete and then re-insert the referenced key. Since the key
> value is back in the table, I would expect the delete to NOT cascade, but
> apparently it does.

We've not been able to determine what the "correct" behavior for this is,
the spec is not entirely clear.

The question is what are matching rows and does re-inserting a row that
matches that key value invalidate the mark for deletion, because the SQL92
says basically (11.8):
5) If a <delete rule> is specified and a row of the referenced
table that has not previously been marked for deletion is marked
for deletion, then

Case:

a) If <match type> is not specified or if FULL is specified,
then

Case:

i) If the <delete rule> specifies CASCADE, then all matching
rows are marked for deletion.

It talks about matching rows and the time those are chosen, but we've
never managed a real consensus on what the spec intends. We've had
a couple of arguments about it in the past on -hackers.

> Is there another way to acheive this behavior?
Apart from making a new trigger, I don't think so currently. It's
not too hard to add a check to a copy of the trigger (new versions of no
action already do), but then you're not really using the foreign key
stuff, per se.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2002-10-14 17:24:31 Re: drop constraint unnamed?
Previous Message Justin Clift 2002-10-14 17:01:32 Turkish version of the PostgreSQL "Advocacy and Marketing" site is ready