Skip to content

Commit 5ea47e8

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 a742ef8 commit 5ea47e8

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
@@ -14713,8 +14713,8 @@ dumpConstraint(Archive *fout, DumpOptions *dopt, ConstraintInfo *coninfo)
1471314713
{
1471414714
/* CHECK constraint on a table */
1471514715

14716-
/* Ignore if not to be dumped separately */
14717-
if (coninfo->separate)
14716+
/* Ignore if not to be dumped separately, or if it was inherited */
14717+
if (coninfo->separate && coninfo->conislocal)
1471814718
{
1471914719
/* not ONLY since we want it to propagate to children */
1472014720
appendPQExpBuffer(q, "ALTER TABLE %s\n",

src/test/regress/expected/alter_table.out

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

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

src/test/regress/sql/alter_table.sql

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

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

344348
-- Foreign key adding test with mixed types
345349

0 commit comments

Comments
 (0)