Skip to content

Commit 35435af

Browse files
committed
Fix pg_dump to handle inherited NOT VALID check constraints correctly.
This case seems to have been overlooked when unvalidated check constraints were introduced, in 9.2. The code would attempt to dump such constraints over again for each child table, even though adding them to the parent table is sufficient. In 9.2 and 9.3, also fix contrib/pg_upgrade/Makefile so that the "make clean" target fully cleans up after a failed test. This evidently got dealt with at some point in 9.4, but it wasn't back-patched. I ran into it while testing this fix ... Per bug #13656 from Ingmar Brouns.
1 parent 1128b77 commit 35435af

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

src/bin/pg_dump/pg_dump.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -14114,8 +14114,8 @@ dumpConstraint(Archive *fout, ConstraintInfo *coninfo)
1411414114
{
1411514115
/* CHECK constraint on a table */
1411614116

14117-
/* Ignore if not to be dumped separately */
14118-
if (coninfo->separate)
14117+
/* Ignore if not to be dumped separately, or if it was inherited */
14118+
if (coninfo->separate && coninfo->conislocal)
1411914119
{
1412014120
/* not ONLY since we want it to propagate to children */
1412114121
appendPQExpBuffer(q, "ALTER TABLE %s\n",

src/test/regress/expected/alter_table.out

+13
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,19 @@ explain (costs off) select * from nv_parent where d between '2009-08-01'::date a
436436
Filter: ((d >= '08-01-2009'::date) AND (d <= '08-31-2009'::date))
437437
(7 rows)
438438

439+
-- add an inherited NOT VALID constraint
440+
alter table nv_parent add check (d between '2001-01-01'::date and '2099-12-31'::date) not valid;
441+
\d nv_child_2009
442+
Table "public.nv_child_2009"
443+
Column | Type | Modifiers
444+
--------+------+-----------
445+
d | date |
446+
Check constraints:
447+
"nv_child_2009_d_check" CHECK (d >= '01-01-2009'::date AND d <= '12-31-2009'::date)
448+
"nv_parent_d_check" CHECK (d >= '01-01-2001'::date AND d <= '12-31-2099'::date) NOT VALID
449+
Inherits: nv_parent
450+
451+
-- we leave nv_parent and children around to help test pg_dump logic
439452
-- Foreign key adding test with mixed types
440453
-- Note: these tables are TEMP to avoid name conflicts when this test
441454
-- is run in parallel with foreign_key.sql.

src/test/regress/sql/alter_table.sql

+4
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,10 @@ explain (costs off) select * from nv_parent where d between '2009-08-01'::date a
339339
alter table nv_child_2011 VALIDATE CONSTRAINT nv_child_2011_d_check;
340340
explain (costs off) select * from nv_parent where d between '2009-08-01'::date and '2009-08-31'::date;
341341

342+
-- add an inherited NOT VALID constraint
343+
alter table nv_parent add check (d between '2001-01-01'::date and '2099-12-31'::date) not valid;
344+
\d nv_child_2009
345+
-- we leave nv_parent and children around to help test pg_dump logic
342346

343347
-- Foreign key adding test with mixed types
344348

0 commit comments

Comments
 (0)