Skip to content

Commit 304e9f0

Browse files
committed
Increase test coverage in RI_Initial_Check()
This covers the special error handling of FKCONSTR_MATCH_FULL. Reviewed-by: Alvaro Herrera <alvherre@2ndquadrant.com> Reviewed-by: Mi Tar <mmitar@gmail.com> Discussion: https://www.postgresql.org/message-id/flat/7ae17c95-0c99-d420-032a-c271f510112b@2ndquadrant.com/
1 parent 45ed6e1 commit 304e9f0

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

src/test/regress/expected/foreign_key.out

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,18 @@ SELECT * FROM PKTABLE;
339339
0 | Test4
340340
(4 rows)
341341

342+
DROP TABLE FKTABLE;
343+
DROP TABLE PKTABLE;
344+
--
345+
-- Check initial check upon ALTER TABLE
346+
--
347+
CREATE TABLE PKTABLE ( ptest1 int, ptest2 int, PRIMARY KEY(ptest1, ptest2) );
348+
CREATE TABLE FKTABLE ( ftest1 int, ftest2 int );
349+
INSERT INTO PKTABLE VALUES (1, 2);
350+
INSERT INTO FKTABLE VALUES (1, NULL);
351+
ALTER TABLE FKTABLE ADD FOREIGN KEY(ftest1, ftest2) REFERENCES PKTABLE MATCH FULL;
352+
ERROR: insert or update on table "fktable" violates foreign key constraint "fktable_ftest1_fkey"
353+
DETAIL: MATCH FULL does not allow mixing of null and nonnull key values.
342354
DROP TABLE FKTABLE;
343355
DROP TABLE PKTABLE;
344356
-- MATCH SIMPLE
@@ -1607,6 +1619,11 @@ INSERT INTO fk_partitioned_fk (a,b) VALUES (NULL, NULL);
16071619
INSERT INTO fk_notpartitioned_pk VALUES (1, 2);
16081620
CREATE TABLE fk_partitioned_fk_full (x int, y int) PARTITION BY RANGE (x);
16091621
CREATE TABLE fk_partitioned_fk_full_1 PARTITION OF fk_partitioned_fk_full DEFAULT;
1622+
INSERT INTO fk_partitioned_fk_full VALUES (1, NULL);
1623+
ALTER TABLE fk_partitioned_fk_full ADD FOREIGN KEY (x, y) REFERENCES fk_notpartitioned_pk MATCH FULL; -- fails
1624+
ERROR: insert or update on table "fk_partitioned_fk_full" violates foreign key constraint "fk_partitioned_fk_full_x_fkey"
1625+
DETAIL: MATCH FULL does not allow mixing of null and nonnull key values.
1626+
TRUNCATE fk_partitioned_fk_full;
16101627
ALTER TABLE fk_partitioned_fk_full ADD FOREIGN KEY (x, y) REFERENCES fk_notpartitioned_pk MATCH FULL;
16111628
INSERT INTO fk_partitioned_fk_full VALUES (1, NULL); -- fails
16121629
ERROR: insert or update on table "fk_partitioned_fk_full_1" violates foreign key constraint "fk_partitioned_fk_full_x_fkey"

src/test/regress/sql/foreign_key.sql

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,20 @@ SELECT * FROM PKTABLE;
219219
DROP TABLE FKTABLE;
220220
DROP TABLE PKTABLE;
221221

222+
--
223+
-- Check initial check upon ALTER TABLE
224+
--
225+
CREATE TABLE PKTABLE ( ptest1 int, ptest2 int, PRIMARY KEY(ptest1, ptest2) );
226+
CREATE TABLE FKTABLE ( ftest1 int, ftest2 int );
227+
228+
INSERT INTO PKTABLE VALUES (1, 2);
229+
INSERT INTO FKTABLE VALUES (1, NULL);
230+
231+
ALTER TABLE FKTABLE ADD FOREIGN KEY(ftest1, ftest2) REFERENCES PKTABLE MATCH FULL;
232+
233+
DROP TABLE FKTABLE;
234+
DROP TABLE PKTABLE;
235+
222236

223237
-- MATCH SIMPLE
224238

@@ -1214,6 +1228,9 @@ INSERT INTO fk_partitioned_fk (a,b) VALUES (NULL, NULL);
12141228
INSERT INTO fk_notpartitioned_pk VALUES (1, 2);
12151229
CREATE TABLE fk_partitioned_fk_full (x int, y int) PARTITION BY RANGE (x);
12161230
CREATE TABLE fk_partitioned_fk_full_1 PARTITION OF fk_partitioned_fk_full DEFAULT;
1231+
INSERT INTO fk_partitioned_fk_full VALUES (1, NULL);
1232+
ALTER TABLE fk_partitioned_fk_full ADD FOREIGN KEY (x, y) REFERENCES fk_notpartitioned_pk MATCH FULL; -- fails
1233+
TRUNCATE fk_partitioned_fk_full;
12171234
ALTER TABLE fk_partitioned_fk_full ADD FOREIGN KEY (x, y) REFERENCES fk_notpartitioned_pk MATCH FULL;
12181235
INSERT INTO fk_partitioned_fk_full VALUES (1, NULL); -- fails
12191236
DROP TABLE fk_partitioned_fk_full;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy