Skip to content

Commit

Permalink
pg_dump: fix failure to dump comments on constraints in some cases.
Browse files Browse the repository at this point in the history
Thinko in commit 5209c0b: I checked the wrong object's
DUMP_COMPONENT_COMMENT bit in two places.

Per bug #17675 from Franz-Josef Färber.

Discussion: https://postgr.es/m/17675-c69c001e06390867@postgresql.org
  • Loading branch information
tglsfdc committed Nov 2, 2022
1 parent d54e79b commit 26ee7fb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/bin/pg_dump/pg_dump.c
Expand Up @@ -10996,7 +10996,7 @@ dumpDomain(Archive *fout, const TypeInfo *tyinfo)
appendPQExpBuffer(conprefix, "CONSTRAINT %s ON DOMAIN",
fmtId(domcheck->dobj.name));

if (tyinfo->dobj.dump & DUMP_COMPONENT_COMMENT)
if (domcheck->dobj.dump & DUMP_COMPONENT_COMMENT)
dumpComment(fout, conprefix->data, qtypname,
tyinfo->dobj.namespace->dobj.name,
tyinfo->rolname,
Expand Down Expand Up @@ -15868,7 +15868,7 @@ dumpTableSchema(Archive *fout, const TableInfo *tbinfo)
if (constr->separate || !constr->conislocal)
continue;

if (tbinfo->dobj.dump & DUMP_COMPONENT_COMMENT)
if (constr->dobj.dump & DUMP_COMPONENT_COMMENT)
dumpTableConstraintComment(fout, constr);
}

Expand Down
15 changes: 11 additions & 4 deletions src/bin/pg_dump/t/002_pg_dump.pl
Expand Up @@ -1690,13 +1690,16 @@
COLLATE "C"
DEFAULT \'10014\'
CHECK(VALUE ~ \'^\d{5}$\' OR
VALUE ~ \'^\d{5}-\d{4}$\');',
VALUE ~ \'^\d{5}-\d{4}$\');
COMMENT ON CONSTRAINT us_postal_code_check
ON DOMAIN dump_test.us_postal_code IS \'check it\';',
regexp => qr/^
\QCREATE DOMAIN dump_test.us_postal_code AS text COLLATE pg_catalog."C" DEFAULT '10014'::text\E\n\s+
\QCONSTRAINT us_postal_code_check CHECK \E
\Q(((VALUE ~ '^\d{5}\E
\$\Q'::text) OR (VALUE ~ '^\d{5}-\d{4}\E\$
\Q'::text)));\E
\Q'::text)));\E(.|\n)*
\QCOMMENT ON CONSTRAINT us_postal_code_check ON DOMAIN dump_test.us_postal_code IS 'check it';\E
/xm,
like =>
{ %full_runs, %dump_test_schema_runs, section_pre_data => 1, },
Expand Down Expand Up @@ -2639,7 +2642,9 @@
col3 text,
col4 text,
CHECK (col1 <= 1000)
) WITH (autovacuum_enabled = false, fillfactor=80);',
) WITH (autovacuum_enabled = false, fillfactor=80);
COMMENT ON CONSTRAINT test_table_col1_check
ON dump_test.test_table IS \'bounds check\';',
regexp => qr/^
\QCREATE TABLE dump_test.test_table (\E\n
\s+\Qcol1 integer NOT NULL,\E\n
Expand All @@ -2648,7 +2653,9 @@
\s+\Qcol4 text,\E\n
\s+\QCONSTRAINT test_table_col1_check CHECK ((col1 <= 1000))\E\n
\Q)\E\n
\QWITH (autovacuum_enabled='false', fillfactor='80');\E\n/xm,
\QWITH (autovacuum_enabled='false', fillfactor='80');\E\n(.|\n)*
\QCOMMENT ON CONSTRAINT test_table_col1_check ON dump_test.test_table IS 'bounds check';\E
/xm,
like => {
%full_runs,
%dump_test_schema_runs,
Expand Down

0 comments on commit 26ee7fb

Please sign in to comment.