Skip to content

Commit e04aca1

Browse files
author
Álvaro Herrera
committed
Fix dumping of comments on invalid constraints on domains
We skip dumping constraints together with domains if they are invalid ('separate') so that they appear after data -- but their comments were dumped together with the domain definition, which in effect leads to the comment being dumped when the constraint does not yet exist. Delay them in the same way. Oversight in 7eca575; backpatch all the way back. Author: jian he <jian.universality@gmail.com> Discussion: https://postgr.es/m/CACJufxF_C2pe6J_+nPr6C5jf5rQnbYP8XOKr4HM8yHZtp2aQqQ@mail.gmail.com
1 parent 0490d6e commit e04aca1

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

src/bin/pg_dump/pg_dump.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11638,8 +11638,13 @@ dumpDomain(Archive *fout, const TypeInfo *tyinfo)
1163811638
for (i = 0; i < tyinfo->nDomChecks; i++)
1163911639
{
1164011640
ConstraintInfo *domcheck = &(tyinfo->domChecks[i]);
11641-
PQExpBuffer conprefix = createPQExpBuffer();
11641+
PQExpBuffer conprefix;
1164211642

11643+
/* but only if the constraint itself was dumped here */
11644+
if (domcheck->separate)
11645+
continue;
11646+
11647+
conprefix = createPQExpBuffer();
1164311648
appendPQExpBuffer(conprefix, "CONSTRAINT %s ON DOMAIN",
1164411649
fmtId(domcheck->dobj.name));
1164511650

@@ -17495,6 +17500,22 @@ dumpConstraint(Archive *fout, const ConstraintInfo *coninfo)
1749517500
.section = SECTION_POST_DATA,
1749617501
.createStmt = q->data,
1749717502
.dropStmt = delq->data));
17503+
17504+
if (coninfo->dobj.dump & DUMP_COMPONENT_COMMENT)
17505+
{
17506+
PQExpBuffer conprefix = createPQExpBuffer();
17507+
char *qtypname = pg_strdup(fmtId(tyinfo->dobj.name));
17508+
17509+
appendPQExpBuffer(conprefix, "CONSTRAINT %s ON DOMAIN",
17510+
fmtId(coninfo->dobj.name));
17511+
17512+
dumpComment(fout, conprefix->data, qtypname,
17513+
tyinfo->dobj.namespace->dobj.name,
17514+
tyinfo->rolname,
17515+
coninfo->dobj.catId, 0, tyinfo->dobj.dumpId);
17516+
destroyPQExpBuffer(conprefix);
17517+
free(qtypname);
17518+
}
1749817519
}
1749917520
}
1750017521
else

src/test/regress/input/constraints.source

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,3 +612,9 @@ DROP DOMAIN constraint_comments_dom;
612612

613613
DROP ROLE regress_constraint_comments;
614614
DROP ROLE regress_constraint_comments_noaccess;
615+
616+
-- Leave some constraints for the pg_upgrade test to pick up
617+
CREATE DOMAIN constraint_comments_dom AS int;
618+
619+
ALTER DOMAIN constraint_comments_dom ADD CONSTRAINT inv_ck CHECK (value > 0) NOT VALID;
620+
COMMENT ON CONSTRAINT inv_ck ON DOMAIN constraint_comments_dom IS 'comment on invalid constraint';

src/test/regress/output/constraints.source

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,3 +802,7 @@ DROP TABLE constraint_comments_tbl;
802802
DROP DOMAIN constraint_comments_dom;
803803
DROP ROLE regress_constraint_comments;
804804
DROP ROLE regress_constraint_comments_noaccess;
805+
-- Leave some constraints for the pg_upgrade test to pick up
806+
CREATE DOMAIN constraint_comments_dom AS int;
807+
ALTER DOMAIN constraint_comments_dom ADD CONSTRAINT inv_ck CHECK (value > 0) NOT VALID;
808+
COMMENT ON CONSTRAINT inv_ck ON DOMAIN constraint_comments_dom IS 'comment on invalid constraint';

0 commit comments

Comments
 (0)