Foreign Key Deferrable Misunderstanding or Bug?

Started by Paul Rogersover 16 years ago3 messagesgeneral
Jump to latest
#1Paul Rogers
progers@sparkbase.com

Why does the attached script fail with a foreign key constraint violation?

Privileged/Confidential Information may be contained in this message.

If you are not the addressee indicated in this message (or responsible for delivery of the message to such person), you may not copy or deliver this message to anyone. In such case, you should destroy this message and kindly notify the sender by reply email. Please advise immediately if you or your employer does not consent to Internet email for messages of this kind. Opinions, conclusions and other information in this message that do not relate to the official business of my firm shall be understood as neither given nor endorsed by it.

Attachments:

test-fk-def.sqltext/x-sql; name=test-fk-def.sqlDownload
#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Paul Rogers (#1)
Re: Foreign Key Deferrable Misunderstanding or Bug?

Paul Rogers <progers@sparkbase.com> writes:

Why does the attached script fail with a foreign key constraint violation?

The ON DELETE RESTRICT is why. Per the fine manual:

[RESTRICT] is the same as NO ACTION except that the check is not
deferrable.

It's a bit odd, but that's the best interpretation we can make of the
spec's wording about how this should work.

regards, tom lane

#3Stephan Szabo
sszabo@megazone23.bigpanda.com
In reply to: Paul Rogers (#1)
Re: Foreign Key Deferrable Misunderstanding or Bug?

On Thu, 6 Aug 2009, Paul Rogers wrote:

Why does the attached script fail with a foreign key constraint violation?

Referential actions are not deferred when a constraint is marked
deferrable (as that appears to be what the spec wants), so ON DELETE
RESTRICT will still fail on the statement, while ON DELETE NO ACTION (ie,
only check at constraint check time) should wait to the end.