Foreign Key Deferrable Misunderstanding or Bug? - Mailing list pgsql-general

From Paul Rogers
Subject Foreign Key Deferrable Misunderstanding or Bug?
Date
Msg-id 4A7B48D6.7000306@sparkbase.com
Whole thread Raw
Responses Re: Foreign Key Deferrable Misunderstanding or Bug?  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: Foreign Key Deferrable Misunderstanding or Bug?  (Stephan Szabo <sszabo@megazone.bigpanda.com>)
List pgsql-general
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
maynot copy or deliver this message to anyone. In such case, you should destroy this message and kindly notify the
senderby reply email. Please advise immediately if you or your employer does not consent to Internet email for messages
ofthis kind. Opinions, conclusions and other information in this message that do not relate to the official business of
myfirm shall be understood as neither given nor endorsed by it. 
DROP TABLE IF EXISTS test_fk_def1 CASCADE;
CREATE TABLE test_fk_def1 (id SERIAL PRIMARY KEY, name TEXT);

DROP TABLE IF EXISTS test_fk_def2 CASCADE;
CREATE TABLE test_fk_def2 (id SERIAL PRIMARY KEY,
  fk INTEGER REFERENCES test_fk_def1(id)
    ON UPDATE CASCADE
    ON DELETE RESTRICT
    DEFERRABLE INITIALLY DEFERRED);

INSERT INTO test_fk_def1 (name) VALUES ('one');
INSERT INTO test_fk_def2 (fk) SELECT id FROM test_fk_def1
    ORDER BY id DESC LIMIT 1;

BEGIN;
-- this should be unnecessary since it is initially deferred, but it doesn't
-- work with or without it
SET CONSTRAINTS test_fk_def2_fk_fkey DEFERRED;
DELETE FROM test_fk_def1; -- why does this fail?
DELETE FROM test_fk_def2;
COMMIT;

pgsql-general by date:

Previous
From: Michael Glaesemann
Date:
Subject: Re: Empty Updates, ON UPDATE triggers and Rules
Next
From: Merlin Moncure
Date:
Subject: Re: Empty Updates, ON UPDATE triggers and Rules