Skip to content

Commit cdaf4a4

Browse files
committed
Increase test coverage in RI_FKey_pk_upd_check_required()
This checks the case where the primary key has at least one null column. 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 74bd066 commit cdaf4a4

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

src/test/regress/expected/foreign_key.out

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,30 @@ SELECT * from FKTABLE;
397397
| 3 | 4 | 5
398398
(5 rows)
399399

400+
DROP TABLE FKTABLE;
401+
DROP TABLE PKTABLE;
402+
-- restrict with null values
403+
CREATE TABLE PKTABLE ( ptest1 int, ptest2 int, ptest3 int, ptest4 text, UNIQUE(ptest1, ptest2, ptest3) );
404+
CREATE TABLE FKTABLE ( ftest1 int, ftest2 int, ftest3 int, ftest4 int, CONSTRAINT constrname3
405+
FOREIGN KEY(ftest1, ftest2, ftest3) REFERENCES PKTABLE (ptest1, ptest2, ptest3));
406+
INSERT INTO PKTABLE VALUES (1, 2, 3, 'test1');
407+
INSERT INTO PKTABLE VALUES (1, 3, NULL, 'test2');
408+
INSERT INTO PKTABLE VALUES (2, NULL, 4, 'test3');
409+
INSERT INTO FKTABLE VALUES (1, 2, 3, 1);
410+
DELETE FROM PKTABLE WHERE ptest1 = 2;
411+
SELECT * FROM PKTABLE;
412+
ptest1 | ptest2 | ptest3 | ptest4
413+
--------+--------+--------+--------
414+
1 | 2 | 3 | test1
415+
1 | 3 | | test2
416+
(2 rows)
417+
418+
SELECT * FROM FKTABLE;
419+
ftest1 | ftest2 | ftest3 | ftest4
420+
--------+--------+--------+--------
421+
1 | 2 | 3 | 1
422+
(1 row)
423+
400424
DROP TABLE FKTABLE;
401425
DROP TABLE PKTABLE;
402426
-- cascade update/delete

src/test/regress/sql/foreign_key.sql

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,25 @@ SELECT * from FKTABLE;
260260
DROP TABLE FKTABLE;
261261
DROP TABLE PKTABLE;
262262

263+
-- restrict with null values
264+
CREATE TABLE PKTABLE ( ptest1 int, ptest2 int, ptest3 int, ptest4 text, UNIQUE(ptest1, ptest2, ptest3) );
265+
CREATE TABLE FKTABLE ( ftest1 int, ftest2 int, ftest3 int, ftest4 int, CONSTRAINT constrname3
266+
FOREIGN KEY(ftest1, ftest2, ftest3) REFERENCES PKTABLE (ptest1, ptest2, ptest3));
267+
268+
INSERT INTO PKTABLE VALUES (1, 2, 3, 'test1');
269+
INSERT INTO PKTABLE VALUES (1, 3, NULL, 'test2');
270+
INSERT INTO PKTABLE VALUES (2, NULL, 4, 'test3');
271+
272+
INSERT INTO FKTABLE VALUES (1, 2, 3, 1);
273+
274+
DELETE FROM PKTABLE WHERE ptest1 = 2;
275+
276+
SELECT * FROM PKTABLE;
277+
SELECT * FROM FKTABLE;
278+
279+
DROP TABLE FKTABLE;
280+
DROP TABLE PKTABLE;
281+
263282
-- cascade update/delete
264283
CREATE TABLE PKTABLE ( ptest1 int, ptest2 int, ptest3 int, ptest4 text, PRIMARY KEY(ptest1, ptest2, ptest3) );
265284
CREATE TABLE FKTABLE ( ftest1 int, ftest2 int, ftest3 int, ftest4 int, CONSTRAINT constrname3

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