Skip to content

Commit d07bc7c

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 c0a392c commit d07bc7c

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
@@ -11623,8 +11623,13 @@ dumpDomain(Archive *fout, const TypeInfo *tyinfo)
1162311623
for (i = 0; i < tyinfo->nDomChecks; i++)
1162411624
{
1162511625
ConstraintInfo *domcheck = &(tyinfo->domChecks[i]);
11626-
PQExpBuffer conprefix = createPQExpBuffer();
11626+
PQExpBuffer conprefix;
1162711627

11628+
/* but only if the constraint itself was dumped here */
11629+
if (domcheck->separate)
11630+
continue;
11631+
11632+
conprefix = createPQExpBuffer();
1162811633
appendPQExpBuffer(conprefix, "CONSTRAINT %s ON DOMAIN",
1162911634
fmtId(domcheck->dobj.name));
1163011635

@@ -17361,6 +17366,22 @@ dumpConstraint(Archive *fout, const ConstraintInfo *coninfo)
1736117366
.section = SECTION_POST_DATA,
1736217367
.createStmt = q->data,
1736317368
.dropStmt = delq->data));
17369+
17370+
if (coninfo->dobj.dump & DUMP_COMPONENT_COMMENT)
17371+
{
17372+
PQExpBuffer conprefix = createPQExpBuffer();
17373+
char *qtypname = pg_strdup(fmtId(tyinfo->dobj.name));
17374+
17375+
appendPQExpBuffer(conprefix, "CONSTRAINT %s ON DOMAIN",
17376+
fmtId(coninfo->dobj.name));
17377+
17378+
dumpComment(fout, conprefix->data, qtypname,
17379+
tyinfo->dobj.namespace->dobj.name,
17380+
tyinfo->rolname,
17381+
coninfo->dobj.catId, 0, tyinfo->dobj.dumpId);
17382+
destroyPQExpBuffer(conprefix);
17383+
free(qtypname);
17384+
}
1736417385
}
1736517386
}
1736617387
else

src/test/regress/expected/constraints.out

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -830,3 +830,7 @@ DROP TABLE constraint_comments_tbl;
830830
DROP DOMAIN constraint_comments_dom;
831831
DROP ROLE regress_constraint_comments;
832832
DROP ROLE regress_constraint_comments_noaccess;
833+
-- Leave some constraints for the pg_upgrade test to pick up
834+
CREATE DOMAIN constraint_comments_dom AS int;
835+
ALTER DOMAIN constraint_comments_dom ADD CONSTRAINT inv_ck CHECK (value > 0) NOT VALID;
836+
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
@@ -632,3 +632,9 @@ DROP DOMAIN constraint_comments_dom;
632632

633633
DROP ROLE regress_constraint_comments;
634634
DROP ROLE regress_constraint_comments_noaccess;
635+
636+
-- Leave some constraints for the pg_upgrade test to pick up
637+
CREATE DOMAIN constraint_comments_dom AS int;
638+
639+
ALTER DOMAIN constraint_comments_dom ADD CONSTRAINT inv_ck CHECK (value > 0) NOT VALID;
640+
COMMENT ON CONSTRAINT inv_ck ON DOMAIN constraint_comments_dom IS 'comment on invalid constraint';

0 commit comments

Comments
 (0)