From 98e3a93d90ff21a18a95e759ac49b04b58c1cf70 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Wed, 21 Nov 2018 13:18:14 +0100 Subject: [PATCH 3/4] Increase test coverage in RI_FKey_fk_upd_check_required() This checks the code path of FKCONSTR_MATCH_FULL and RI_KEYS_SOME_NULL. --- src/test/regress/expected/foreign_key.out | 8 +++++++- src/test/regress/sql/foreign_key.sql | 6 ++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/test/regress/expected/foreign_key.out b/src/test/regress/expected/foreign_key.out index 421ffbeae7..6b2df98c7e 100644 --- a/src/test/regress/expected/foreign_key.out +++ b/src/test/regress/expected/foreign_key.out @@ -143,6 +143,12 @@ SELECT * FROM FKTABLE; | | 8 (5 rows) +-- Check update with part of key null +UPDATE FKTABLE SET ftest1 = NULL WHERE ftest1 = 1; +ERROR: insert or update on table "fktable" violates foreign key constraint "constrname" +DETAIL: MATCH FULL does not allow mixing of null and nonnull key values. +-- Check update with old and new key values equal +UPDATE FKTABLE SET ftest1 = 1 WHERE ftest1 = 1; -- Try altering the column type where foreign keys are involved ALTER TABLE PKTABLE ALTER COLUMN ptest1 TYPE bigint; ALTER TABLE FKTABLE ALTER COLUMN ftest1 TYPE bigint; @@ -158,11 +164,11 @@ SELECT * FROM PKTABLE; SELECT * FROM FKTABLE; ftest1 | ftest2 | ftest3 --------+--------+-------- - 1 | 3 | 5 3 | 6 | 12 | | 0 | | 4 | | 8 + 1 | 3 | 5 (5 rows) DROP TABLE PKTABLE CASCADE; diff --git a/src/test/regress/sql/foreign_key.sql b/src/test/regress/sql/foreign_key.sql index d3ed72b1fc..9dd5e29c75 100644 --- a/src/test/regress/sql/foreign_key.sql +++ b/src/test/regress/sql/foreign_key.sql @@ -97,6 +97,12 @@ CREATE TABLE FKTABLE ( ftest1 int, ftest2 int, ftest3 int, CONSTRAINT constrname -- Check FKTABLE for update of matched row SELECT * FROM FKTABLE; +-- Check update with part of key null +UPDATE FKTABLE SET ftest1 = NULL WHERE ftest1 = 1; + +-- Check update with old and new key values equal +UPDATE FKTABLE SET ftest1 = 1 WHERE ftest1 = 1; + -- Try altering the column type where foreign keys are involved ALTER TABLE PKTABLE ALTER COLUMN ptest1 TYPE bigint; ALTER TABLE FKTABLE ALTER COLUMN ftest1 TYPE bigint; -- 2.19.2