Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1e5a16c

Browse files
committed
The deferred trigger queue pushing to disk patch pointed out
that the regression tests for foreign keys didn't seem to test a deferred constraint that was not satisified by a later statement and was not made immediate by set constraints, so here's a simple added test with a single invalid insert and a commit. Stephan Szabo
1 parent 1be17f1 commit 1e5a16c

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

src/test/regress/expected/foreign_key.out

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,3 +1053,22 @@ INSERT INTO pktable VALUES (2000, 3); -- too late
10531053
ERROR: current transaction is aborted, queries ignored until end of transaction block
10541054
COMMIT;
10551055
DROP TABLE fktable, pktable;
1056+
-- deferrable, initially deferred
1057+
CREATE TABLE pktable (
1058+
id INT4 PRIMARY KEY,
1059+
other INT4
1060+
);
1061+
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "pktable_pkey" for table "pktable"
1062+
CREATE TABLE fktable (
1063+
id INT4 PRIMARY KEY,
1064+
fk INT4 REFERENCES pktable DEFERRABLE INITIALLY DEFERRED
1065+
);
1066+
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "fktable_pkey" for table "fktable"
1067+
NOTICE: CREATE TABLE will create implicit trigger(s) for FOREIGN KEY check(s)
1068+
BEGIN;
1069+
-- no error here
1070+
INSERT INTO fktable VALUES (100, 200);
1071+
-- error here on commit
1072+
COMMIT;
1073+
ERROR: insert or update on "fktable" violates foreign key constraint "$1"
1074+
DETAIL: Key (fk)=(200) is not present in "pktable".

src/test/regress/sql/foreign_key.sql

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,3 +674,23 @@ INSERT INTO pktable VALUES (2000, 3); -- too late
674674
COMMIT;
675675

676676
DROP TABLE fktable, pktable;
677+
678+
-- deferrable, initially deferred
679+
CREATE TABLE pktable (
680+
id INT4 PRIMARY KEY,
681+
other INT4
682+
);
683+
684+
CREATE TABLE fktable (
685+
id INT4 PRIMARY KEY,
686+
fk INT4 REFERENCES pktable DEFERRABLE INITIALLY DEFERRED
687+
);
688+
689+
BEGIN;
690+
691+
-- no error here
692+
INSERT INTO fktable VALUES (100, 200);
693+
694+
-- error here on commit
695+
COMMIT;
696+

0 commit comments

Comments
 (0)