From f27a6b15e6566fba7748d0d9a3fc5bcfd52c4a1b Mon Sep 17 00:00:00 2001 From: Robert Haas Date: Wed, 16 Dec 2015 07:43:56 -0500 Subject: Mark CHECK constraints declared NOT VALID valid if created with table. FOREIGN KEY constraints have behaved this way for a long time, but for some reason the behavior of CHECK constraints has been inconsistent up until now. Amit Langote and Amul Sul, with assorted tweaks by me. --- src/test/regress/expected/alter_table.out | 11 ++++++++++- src/test/regress/sql/alter_table.sql | 5 ++++- 2 files changed, 14 insertions(+), 2 deletions(-) (limited to 'src/test') diff --git a/src/test/regress/expected/alter_table.out b/src/test/regress/expected/alter_table.out index 61669b6c7f1..228ae6ec221 100644 --- a/src/test/regress/expected/alter_table.out +++ b/src/test/regress/expected/alter_table.out @@ -380,7 +380,16 @@ DROP TABLE tmp2; -- NOT VALID with plan invalidation -- ensure we don't use a constraint for -- exclusion until validated set constraint_exclusion TO 'partition'; -create table nv_parent (d date); +create table nv_parent (d date, check (false) no inherit not valid); +-- not valid constraint added at creation time should automatically become valid +\d nv_parent + Table "public.nv_parent" + Column | Type | Modifiers +--------+------+----------- + d | date | +Check constraints: + "nv_parent_check" CHECK (false) NO INHERIT + create table nv_child_2010 () inherits (nv_parent); create table nv_child_2011 () inherits (nv_parent); alter table nv_child_2010 add check (d between '2010-01-01'::date and '2010-12-31'::date) not valid; diff --git a/src/test/regress/sql/alter_table.sql b/src/test/regress/sql/alter_table.sql index c0bb77ee221..3db34609733 100644 --- a/src/test/regress/sql/alter_table.sql +++ b/src/test/regress/sql/alter_table.sql @@ -327,7 +327,10 @@ DROP TABLE tmp2; -- NOT VALID with plan invalidation -- ensure we don't use a constraint for -- exclusion until validated set constraint_exclusion TO 'partition'; -create table nv_parent (d date); +create table nv_parent (d date, check (false) no inherit not valid); +-- not valid constraint added at creation time should automatically become valid +\d nv_parent + create table nv_child_2010 () inherits (nv_parent); create table nv_child_2011 () inherits (nv_parent); alter table nv_child_2010 add check (d between '2010-01-01'::date and '2010-12-31'::date) not valid; -- cgit v1.2.3