summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/bin/pg_dump/pg_dump.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c
index 1c02ee824c3..b1c4f8d12e3 100644
--- a/src/bin/pg_dump/pg_dump.c
+++ b/src/bin/pg_dump/pg_dump.c
@@ -10352,6 +10352,7 @@ static void
dumpIndex(Archive *fout, IndxInfo *indxinfo)
{
TableInfo *tbinfo = indxinfo->indextable;
+ bool is_constraint = (indxinfo->indexconstraint != 0);
PQExpBuffer q;
PQExpBuffer delq;
@@ -10364,9 +10365,11 @@ dumpIndex(Archive *fout, IndxInfo *indxinfo)
/*
* If there's an associated constraint, don't dump the index per se, but
* do dump any comment for it. (This is safe because dependency ordering
- * will have ensured the constraint is emitted first.)
+ * will have ensured the constraint is emitted first.) Note that the
+ * emitted comment has to be shown as depending on the constraint, not
+ * the index, in such cases.
*/
- if (indxinfo->indexconstraint == 0)
+ if (!is_constraint)
{
/* Plain secondary index */
appendPQExpBuffer(q, "%s;\n", indxinfo->indexdef);
@@ -10407,7 +10410,9 @@ dumpIndex(Archive *fout, IndxInfo *indxinfo)
dumpComment(fout, q->data,
tbinfo->dobj.namespace->dobj.name,
tbinfo->rolname,
- indxinfo->dobj.catId, 0, indxinfo->dobj.dumpId);
+ indxinfo->dobj.catId, 0,
+ is_constraint ? indxinfo->indexconstraint :
+ indxinfo->dobj.dumpId);
destroyPQExpBuffer(q);
destroyPQExpBuffer(delq);