Skip to content

Commit dca0e96

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 973caf7 commit dca0e96

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
@@ -12583,8 +12583,13 @@ dumpDomain(Archive *fout, const TypeInfo *tyinfo)
1258312583
for (i = 0; i < tyinfo->nDomChecks; i++)
1258412584
{
1258512585
ConstraintInfo *domcheck = &(tyinfo->domChecks[i]);
12586-
PQExpBuffer conprefix = createPQExpBuffer();
12586+
PQExpBuffer conprefix;
1258712587

12588+
/* but only if the constraint itself was dumped here */
12589+
if (domcheck->separate)
12590+
continue;
12591+
12592+
conprefix = createPQExpBuffer();
1258812593
appendPQExpBuffer(conprefix, "CONSTRAINT %s ON DOMAIN",
1258912594
fmtId(domcheck->dobj.name));
1259012595

@@ -18488,6 +18493,22 @@ dumpConstraint(Archive *fout, const ConstraintInfo *coninfo)
1848818493
.section = SECTION_POST_DATA,
1848918494
.createStmt = q->data,
1849018495
.dropStmt = delq->data));
18496+
18497+
if (coninfo->dobj.dump & DUMP_COMPONENT_COMMENT)
18498+
{
18499+
PQExpBuffer conprefix = createPQExpBuffer();
18500+
char *qtypname = pg_strdup(fmtId(tyinfo->dobj.name));
18501+
18502+
appendPQExpBuffer(conprefix, "CONSTRAINT %s ON DOMAIN",
18503+
fmtId(coninfo->dobj.name));
18504+
18505+
dumpComment(fout, conprefix->data, qtypname,
18506+
tyinfo->dobj.namespace->dobj.name,
18507+
tyinfo->rolname,
18508+
coninfo->dobj.catId, 0, tyinfo->dobj.dumpId);
18509+
destroyPQExpBuffer(conprefix);
18510+
free(qtypname);
18511+
}
1849118512
}
1849218513
}
1849318514
else

src/test/regress/expected/constraints.out

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1701,3 +1701,7 @@ DROP TABLE constraint_comments_tbl;
17011701
DROP DOMAIN constraint_comments_dom;
17021702
DROP ROLE regress_constraint_comments;
17031703
DROP ROLE regress_constraint_comments_noaccess;
1704+
-- Leave some constraints for the pg_upgrade test to pick up
1705+
CREATE DOMAIN constraint_comments_dom AS int;
1706+
ALTER DOMAIN constraint_comments_dom ADD CONSTRAINT inv_ck CHECK (value > 0) NOT VALID;
1707+
COMMENT ON CONSTRAINT inv_ck ON DOMAIN constraint_comments_dom IS 'comment on invalid constraint';

src/test/regress/sql/constraints.sql

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

10441044
DROP ROLE regress_constraint_comments;
10451045
DROP ROLE regress_constraint_comments_noaccess;
1046+
1047+
-- Leave some constraints for the pg_upgrade test to pick up
1048+
CREATE DOMAIN constraint_comments_dom AS int;
1049+
1050+
ALTER DOMAIN constraint_comments_dom ADD CONSTRAINT inv_ck CHECK (value > 0) NOT VALID;
1051+
COMMENT ON CONSTRAINT inv_ck ON DOMAIN constraint_comments_dom IS 'comment on invalid constraint';

0 commit comments

Comments
 (0)