1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-18 17:42:25 +03:00

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 7eca575d1c28; backpatch all the way back.

Author: jian he <jian.universality@gmail.com>
Discussion: https://postgr.es/m/CACJufxF_C2pe6J_+nPr6C5jf5rQnbYP8XOKr4HM8yHZtp2aQqQ@mail.gmail.com
This commit is contained in:
Álvaro Herrera
2025-07-16 19:22:53 +02:00
parent 4c8ad67a98
commit 0858f0f96e
3 changed files with 32 additions and 1 deletions

View File

@ -12583,8 +12583,13 @@ dumpDomain(Archive *fout, const TypeInfo *tyinfo)
for (i = 0; i < tyinfo->nDomChecks; i++) for (i = 0; i < tyinfo->nDomChecks; i++)
{ {
ConstraintInfo *domcheck = &(tyinfo->domChecks[i]); ConstraintInfo *domcheck = &(tyinfo->domChecks[i]);
PQExpBuffer conprefix = createPQExpBuffer(); PQExpBuffer conprefix;
/* but only if the constraint itself was dumped here */
if (domcheck->separate)
continue;
conprefix = createPQExpBuffer();
appendPQExpBuffer(conprefix, "CONSTRAINT %s ON DOMAIN", appendPQExpBuffer(conprefix, "CONSTRAINT %s ON DOMAIN",
fmtId(domcheck->dobj.name)); fmtId(domcheck->dobj.name));
@ -18488,6 +18493,22 @@ dumpConstraint(Archive *fout, const ConstraintInfo *coninfo)
.section = SECTION_POST_DATA, .section = SECTION_POST_DATA,
.createStmt = q->data, .createStmt = q->data,
.dropStmt = delq->data)); .dropStmt = delq->data));
if (coninfo->dobj.dump & DUMP_COMPONENT_COMMENT)
{
PQExpBuffer conprefix = createPQExpBuffer();
char *qtypname = pg_strdup(fmtId(tyinfo->dobj.name));
appendPQExpBuffer(conprefix, "CONSTRAINT %s ON DOMAIN",
fmtId(coninfo->dobj.name));
dumpComment(fout, conprefix->data, qtypname,
tyinfo->dobj.namespace->dobj.name,
tyinfo->rolname,
coninfo->dobj.catId, 0, tyinfo->dobj.dumpId);
destroyPQExpBuffer(conprefix);
free(qtypname);
}
} }
} }
else else

View File

@ -1701,3 +1701,7 @@ DROP TABLE constraint_comments_tbl;
DROP DOMAIN constraint_comments_dom; DROP DOMAIN constraint_comments_dom;
DROP ROLE regress_constraint_comments; DROP ROLE regress_constraint_comments;
DROP ROLE regress_constraint_comments_noaccess; DROP ROLE regress_constraint_comments_noaccess;
-- Leave some constraints for the pg_upgrade test to pick up
CREATE DOMAIN constraint_comments_dom AS int;
ALTER DOMAIN constraint_comments_dom ADD CONSTRAINT inv_ck CHECK (value > 0) NOT VALID;
COMMENT ON CONSTRAINT inv_ck ON DOMAIN constraint_comments_dom IS 'comment on invalid constraint';

View File

@ -1043,3 +1043,9 @@ DROP DOMAIN constraint_comments_dom;
DROP ROLE regress_constraint_comments; DROP ROLE regress_constraint_comments;
DROP ROLE regress_constraint_comments_noaccess; DROP ROLE regress_constraint_comments_noaccess;
-- Leave some constraints for the pg_upgrade test to pick up
CREATE DOMAIN constraint_comments_dom AS int;
ALTER DOMAIN constraint_comments_dom ADD CONSTRAINT inv_ck CHECK (value > 0) NOT VALID;
COMMENT ON CONSTRAINT inv_ck ON DOMAIN constraint_comments_dom IS 'comment on invalid constraint';