pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedBUG #13224: Foreign key constraints cannot be changed to deferrable
2+ messages / 2 participants
[nested] [flat]
* BUG #13224: Foreign key constraints cannot be changed to deferrable
@ 2015-05-03 08:33 chris@chrullrich.net
2015-05-03 14:16 ` Re: BUG #13224: Foreign key constraints cannot be changed to deferrable Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 2+ messages in thread
From: chris@chrullrich.net @ 2015-05-03 08:33 UTC (permalink / raw)
To: pgsql-bugs
The following bug has been logged on the website:
Bug reference: 13224
Logged by: Christian Ullrich
Email address: chris@chrullrich.net
PostgreSQL version: 9.4.1
Operating system: Windows
Description:
According to the manual, ALTER TABLE ... ALTER CONSTRAINT ... DEFERRABLE
should work. It does not, according to the script below.
-- Demonstrates bug related to FK constraints ALTERed to DEFERRABLE.
CREATE TABLE master (
id INTEGER PRIMARY KEY
);
CREATE TABLE detail (
id_master INTEGER REFERENCES master (id),
val TEXT,
PRIMARY KEY (id_master)
);
-- Show the constraint.
SELECT * FROM pg_constraint WHERE conname = 'detail_id_master_fkey';
INSERT INTO master VALUES (1);
INSERT INTO detail VALUES (1, 'one');
-- Fail to change the primary key on the master table (expected).
BEGIN;
UPDATE master SET id = 2 WHERE id = 1;
ROLLBACK;
-- Make the constraint deferrable.
ALTER TABLE detail ALTER CONSTRAINT detail_id_master_fkey DEFERRABLE
INITIALLY IMMEDIATE;
-- Show the constraint. Note condeferrable = true.
SELECT * FROM pg_constraint WHERE conname = 'detail_id_master_fkey';
-- Fail again (unexpected).
BEGIN;
SET CONSTRAINTS ALL DEFERRED;
UPDATE master SET id = 2 WHERE id = 1;
ROLLBACK;
-- Recreate the constraint as deferrable.
ALTER TABLE detail DROP CONSTRAINT detail_id_master_fkey;
ALTER TABLE detail ADD CONSTRAINT detail_id_master_fkey FOREIGN KEY
(id_master) REFERENCES master (id) DEFERRABLE INITIALLY IMMEDIATE;
-- Show the constraint. Note the record is identical to the one from
-- the previous query.
SELECT * FROM pg_constraint WHERE conname = 'detail_id_master_fkey';
-- Succeed this time (expected).
BEGIN;
SET CONSTRAINTS ALL DEFERRED;
UPDATE master SET id = 2 WHERE id = 1;
UPDATE detail SET id_master = 2 WHERE id_master = 1;
COMMIT;
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: BUG #13224: Foreign key constraints cannot be changed to deferrable
2015-05-03 08:33 BUG #13224: Foreign key constraints cannot be changed to deferrable chris@chrullrich.net
@ 2015-05-03 14:16 ` Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 2+ messages in thread
From: Tom Lane @ 2015-05-03 14:16 UTC (permalink / raw)
To: chris@chrullrich.net; +Cc: pgsql-bugs
chris@chrullrich.net writes:
> According to the manual, ALTER TABLE ... ALTER CONSTRAINT ... DEFERRABLE
> should work. It does not, according to the script below.
Hm. It works fine if you cause a reconnect (\c) after the ALTER TABLE.
I suspect the problem is that ATExecAlterConstraint forces a relcache
inval on the named table (detail), but neglects to do so on the other
table (master). The session's cached pg_trigger records for master thus
still say the triggers are nondeferrable.
regards, tom lane
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2015-05-03 14:16 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2015-05-03 08:33 BUG #13224: Foreign key constraints cannot be changed to deferrable chris@chrullrich.net
2015-05-03 14:16 ` Tom Lane <tgl@sss.pgh.pa.us>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox