]> granicus.if.org Git - postgresql/commitdiff
Increase test coverage in RI_Initial_Check()
authorPeter Eisentraut <peter@eisentraut.org>
Wed, 16 Jan 2019 15:53:55 +0000 (16:53 +0100)
committerPeter Eisentraut <peter@eisentraut.org>
Wed, 16 Jan 2019 15:56:18 +0000 (16:56 +0100)
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/

src/test/regress/expected/foreign_key.out
src/test/regress/sql/foreign_key.sql

index 36cbdc0d8a51c0a50e6ad72aed587aa58ae6a7ba..e42e007d4f49c2ee4cb033299fe9cf5eb4fac251 100644 (file)
@@ -339,6 +339,18 @@ SELECT * FROM PKTABLE;
       0 | Test4
 (4 rows)
 
+DROP TABLE FKTABLE;
+DROP TABLE PKTABLE;
+--
+-- Check initial check upon ALTER TABLE
+--
+CREATE TABLE PKTABLE ( ptest1 int, ptest2 int, PRIMARY KEY(ptest1, ptest2) );
+CREATE TABLE FKTABLE ( ftest1 int, ftest2 int );
+INSERT INTO PKTABLE VALUES (1, 2);
+INSERT INTO FKTABLE VALUES (1, NULL);
+ALTER TABLE FKTABLE ADD FOREIGN KEY(ftest1, ftest2) REFERENCES PKTABLE MATCH FULL;
+ERROR:  insert or update on table "fktable" violates foreign key constraint "fktable_ftest1_fkey"
+DETAIL:  MATCH FULL does not allow mixing of null and nonnull key values.
 DROP TABLE FKTABLE;
 DROP TABLE PKTABLE;
 -- MATCH SIMPLE
@@ -1607,6 +1619,11 @@ INSERT INTO fk_partitioned_fk (a,b) VALUES (NULL, NULL);
 INSERT INTO fk_notpartitioned_pk VALUES (1, 2);
 CREATE TABLE fk_partitioned_fk_full (x int, y int) PARTITION BY RANGE (x);
 CREATE TABLE fk_partitioned_fk_full_1 PARTITION OF fk_partitioned_fk_full DEFAULT;
+INSERT INTO fk_partitioned_fk_full VALUES (1, NULL);
+ALTER TABLE fk_partitioned_fk_full ADD FOREIGN KEY (x, y) REFERENCES fk_notpartitioned_pk MATCH FULL;  -- fails
+ERROR:  insert or update on table "fk_partitioned_fk_full" violates foreign key constraint "fk_partitioned_fk_full_x_fkey"
+DETAIL:  MATCH FULL does not allow mixing of null and nonnull key values.
+TRUNCATE fk_partitioned_fk_full;
 ALTER TABLE fk_partitioned_fk_full ADD FOREIGN KEY (x, y) REFERENCES fk_notpartitioned_pk MATCH FULL;
 INSERT INTO fk_partitioned_fk_full VALUES (1, NULL);  -- fails
 ERROR:  insert or update on table "fk_partitioned_fk_full_1" violates foreign key constraint "fk_partitioned_fk_full_x_fkey"
index 2112f24d6b9f51c50f4c151f6b6905ef021a2079..42274f472eb6a26ca07a57c21110d29d3eab4b93 100644 (file)
@@ -219,6 +219,20 @@ SELECT * FROM PKTABLE;
 DROP TABLE FKTABLE;
 DROP TABLE PKTABLE;
 
+--
+-- Check initial check upon ALTER TABLE
+--
+CREATE TABLE PKTABLE ( ptest1 int, ptest2 int, PRIMARY KEY(ptest1, ptest2) );
+CREATE TABLE FKTABLE ( ftest1 int, ftest2 int );
+
+INSERT INTO PKTABLE VALUES (1, 2);
+INSERT INTO FKTABLE VALUES (1, NULL);
+
+ALTER TABLE FKTABLE ADD FOREIGN KEY(ftest1, ftest2) REFERENCES PKTABLE MATCH FULL;
+
+DROP TABLE FKTABLE;
+DROP TABLE PKTABLE;
+
 
 -- MATCH SIMPLE
 
@@ -1214,6 +1228,9 @@ INSERT INTO fk_partitioned_fk (a,b) VALUES (NULL, NULL);
 INSERT INTO fk_notpartitioned_pk VALUES (1, 2);
 CREATE TABLE fk_partitioned_fk_full (x int, y int) PARTITION BY RANGE (x);
 CREATE TABLE fk_partitioned_fk_full_1 PARTITION OF fk_partitioned_fk_full DEFAULT;
+INSERT INTO fk_partitioned_fk_full VALUES (1, NULL);
+ALTER TABLE fk_partitioned_fk_full ADD FOREIGN KEY (x, y) REFERENCES fk_notpartitioned_pk MATCH FULL;  -- fails
+TRUNCATE fk_partitioned_fk_full;
 ALTER TABLE fk_partitioned_fk_full ADD FOREIGN KEY (x, y) REFERENCES fk_notpartitioned_pk MATCH FULL;
 INSERT INTO fk_partitioned_fk_full VALUES (1, NULL);  -- fails
 DROP TABLE fk_partitioned_fk_full;