Skip to content

Commit 57949ce

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 149e6e7 commit 57949ce

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
@@ -11467,8 +11467,13 @@ dumpDomain(Archive *fout, TypeInfo *tyinfo)
1146711467
for (i = 0; i < tyinfo->nDomChecks; i++)
1146811468
{
1146911469
ConstraintInfo *domcheck = &(tyinfo->domChecks[i]);
11470-
PQExpBuffer conprefix = createPQExpBuffer();
11470+
PQExpBuffer conprefix;
1147111471

11472+
/* but only if the constraint itself was dumped here */
11473+
if (domcheck->separate)
11474+
continue;
11475+
11476+
conprefix = createPQExpBuffer();
1147211477
appendPQExpBuffer(conprefix, "CONSTRAINT %s ON DOMAIN",
1147311478
fmtId(domcheck->dobj.name));
1147411479

@@ -17435,6 +17440,22 @@ dumpConstraint(Archive *fout, ConstraintInfo *coninfo)
1743517440
.section = SECTION_POST_DATA,
1743617441
.createStmt = q->data,
1743717442
.dropStmt = delq->data));
17443+
17444+
if (coninfo->dobj.dump & DUMP_COMPONENT_COMMENT)
17445+
{
17446+
PQExpBuffer conprefix = createPQExpBuffer();
17447+
char *qtypname = pg_strdup(fmtId(tyinfo->dobj.name));
17448+
17449+
appendPQExpBuffer(conprefix, "CONSTRAINT %s ON DOMAIN",
17450+
fmtId(coninfo->dobj.name));
17451+
17452+
dumpComment(fout, conprefix->data, qtypname,
17453+
tyinfo->dobj.namespace->dobj.name,
17454+
tyinfo->rolname,
17455+
coninfo->dobj.catId, 0, tyinfo->dobj.dumpId);
17456+
destroyPQExpBuffer(conprefix);
17457+
free(qtypname);
17458+
}
1743817459
}
1743917460
}
1744017461
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)