Commit 3b3fcc4e authored by Peter Eisentraut's avatar Peter Eisentraut

pg_dump: Add table qualifications to some tags

Some object types have names that are only unique for one table.  But
for those we generally didn't put the table name into the dump TOC tag.
So it was impossible to identify these objects if the same name was used
for multiple tables.  This affects policies, column defaults,
constraints, triggers, and rules.

Fix by adding the table name to the TOC tag, so that it now reads
"$schema $table $object".
Reviewed-by: default avatarMichael Paquier <michael.paquier@gmail.com>
parent de94e2af
......@@ -3080,6 +3080,7 @@ dumpPolicy(Archive *fout, PolicyInfo *polinfo)
PQExpBuffer query;
PQExpBuffer delqry;
const char *cmd;
char *tag;
if (dopt->dataOnly)
return;
......@@ -3147,8 +3148,10 @@ dumpPolicy(Archive *fout, PolicyInfo *polinfo)
appendPQExpBuffer(delqry, "DROP POLICY %s", fmtId(polinfo->polname));
appendPQExpBuffer(delqry, " ON %s;\n", fmtId(tbinfo->dobj.name));
tag = psprintf("%s %s", tbinfo->dobj.name, polinfo->dobj.name);
ArchiveEntry(fout, polinfo->dobj.catId, polinfo->dobj.dumpId,
polinfo->dobj.name,
tag,
polinfo->dobj.namespace->dobj.name,
NULL,
tbinfo->rolname, false,
......@@ -3157,6 +3160,7 @@ dumpPolicy(Archive *fout, PolicyInfo *polinfo)
NULL, 0,
NULL, NULL);
free(tag);
destroyPQExpBuffer(query);
destroyPQExpBuffer(delqry);
}
......@@ -14832,6 +14836,7 @@ dumpAttrDef(Archive *fout, AttrDefInfo *adinfo)
int adnum = adinfo->adnum;
PQExpBuffer q;
PQExpBuffer delq;
char *tag;
/* Skip if table definition not to be dumped */
if (!tbinfo->dobj.dump || dopt->dataOnly)
......@@ -14860,8 +14865,10 @@ dumpAttrDef(Archive *fout, AttrDefInfo *adinfo)
appendPQExpBuffer(delq, "ALTER COLUMN %s DROP DEFAULT;\n",
fmtId(tbinfo->attnames[adnum - 1]));
tag = psprintf("%s %s", tbinfo->dobj.name, tbinfo->attnames[adnum - 1]);
ArchiveEntry(fout, adinfo->dobj.catId, adinfo->dobj.dumpId,
tbinfo->attnames[adnum - 1],
tag,
tbinfo->dobj.namespace->dobj.name,
NULL,
tbinfo->rolname,
......@@ -14870,6 +14877,7 @@ dumpAttrDef(Archive *fout, AttrDefInfo *adinfo)
NULL, 0,
NULL, NULL);
free(tag);
destroyPQExpBuffer(q);
destroyPQExpBuffer(delq);
}
......@@ -15010,6 +15018,7 @@ dumpConstraint(Archive *fout, ConstraintInfo *coninfo)
TableInfo *tbinfo = coninfo->contable;
PQExpBuffer q;
PQExpBuffer delq;
char *tag = NULL;
/* Skip if not to be dumped */
if (!coninfo->dobj.dump || dopt->dataOnly)
......@@ -15103,8 +15112,10 @@ dumpConstraint(Archive *fout, ConstraintInfo *coninfo)
appendPQExpBuffer(delq, "DROP CONSTRAINT %s;\n",
fmtId(coninfo->dobj.name));
tag = psprintf("%s %s", tbinfo->dobj.name, coninfo->dobj.name);
ArchiveEntry(fout, coninfo->dobj.catId, coninfo->dobj.dumpId,
coninfo->dobj.name,
tag,
tbinfo->dobj.namespace->dobj.name,
indxinfo->tablespace,
tbinfo->rolname, false,
......@@ -15136,8 +15147,10 @@ dumpConstraint(Archive *fout, ConstraintInfo *coninfo)
appendPQExpBuffer(delq, "DROP CONSTRAINT %s;\n",
fmtId(coninfo->dobj.name));
tag = psprintf("%s %s", tbinfo->dobj.name, coninfo->dobj.name);
ArchiveEntry(fout, coninfo->dobj.catId, coninfo->dobj.dumpId,
coninfo->dobj.name,
tag,
tbinfo->dobj.namespace->dobj.name,
NULL,
tbinfo->rolname, false,
......@@ -15171,8 +15184,10 @@ dumpConstraint(Archive *fout, ConstraintInfo *coninfo)
appendPQExpBuffer(delq, "DROP CONSTRAINT %s;\n",
fmtId(coninfo->dobj.name));
tag = psprintf("%s %s", tbinfo->dobj.name, coninfo->dobj.name);
ArchiveEntry(fout, coninfo->dobj.catId, coninfo->dobj.dumpId,
coninfo->dobj.name,
tag,
tbinfo->dobj.namespace->dobj.name,
NULL,
tbinfo->rolname, false,
......@@ -15207,8 +15222,10 @@ dumpConstraint(Archive *fout, ConstraintInfo *coninfo)
appendPQExpBuffer(delq, "DROP CONSTRAINT %s;\n",
fmtId(coninfo->dobj.name));
tag = psprintf("%s %s", tyinfo->dobj.name, coninfo->dobj.name);
ArchiveEntry(fout, coninfo->dobj.catId, coninfo->dobj.dumpId,
coninfo->dobj.name,
tag,
tyinfo->dobj.namespace->dobj.name,
NULL,
tyinfo->rolname, false,
......@@ -15228,6 +15245,7 @@ dumpConstraint(Archive *fout, ConstraintInfo *coninfo)
if (tbinfo && coninfo->separate)
dumpTableConstraintComment(fout, coninfo);
free(tag);
destroyPQExpBuffer(q);
destroyPQExpBuffer(delq);
}
......@@ -15581,6 +15599,7 @@ dumpTrigger(Archive *fout, TriggerInfo *tginfo)
size_t lentgargs;
const char *p;
int findx;
char *tag;
/*
* we needn't check dobj.dump because TriggerInfo wouldn't have been
......@@ -15757,8 +15776,10 @@ dumpTrigger(Archive *fout, TriggerInfo *tginfo)
appendPQExpBuffer(labelq, "ON %s",
fmtId(tbinfo->dobj.name));
tag = psprintf("%s %s", tbinfo->dobj.name, tginfo->dobj.name);
ArchiveEntry(fout, tginfo->dobj.catId, tginfo->dobj.dumpId,
tginfo->dobj.name,
tag,
tbinfo->dobj.namespace->dobj.name,
NULL,
tbinfo->rolname, false,
......@@ -15771,6 +15792,7 @@ dumpTrigger(Archive *fout, TriggerInfo *tginfo)
tbinfo->dobj.namespace->dobj.name, tbinfo->rolname,
tginfo->dobj.catId, 0, tginfo->dobj.dumpId);
free(tag);
destroyPQExpBuffer(query);
destroyPQExpBuffer(delqry);
destroyPQExpBuffer(labelq);
......@@ -15861,6 +15883,7 @@ dumpRule(Archive *fout, RuleInfo *rinfo)
PQExpBuffer delcmd;
PQExpBuffer labelq;
PGresult *res;
char *tag;
/* Skip if not to be dumped */
if (!rinfo->dobj.dump || dopt->dataOnly)
......@@ -15958,8 +15981,10 @@ dumpRule(Archive *fout, RuleInfo *rinfo)
appendPQExpBuffer(labelq, " ON %s",
fmtId(tbinfo->dobj.name));
tag = psprintf("%s %s", tbinfo->dobj.name, rinfo->dobj.name);
ArchiveEntry(fout, rinfo->dobj.catId, rinfo->dobj.dumpId,
rinfo->dobj.name,
tag,
tbinfo->dobj.namespace->dobj.name,
NULL,
tbinfo->rolname, false,
......@@ -15976,6 +16001,7 @@ dumpRule(Archive *fout, RuleInfo *rinfo)
PQclear(res);
free(tag);
destroyPQExpBuffer(query);
destroyPQExpBuffer(cmd);
destroyPQExpBuffer(delcmd);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment