summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Dunstan2013-06-25 17:45:03 +0000
committerAndrew Dunstan2013-06-25 17:45:03 +0000
commit5734eb2c92a5efd665186c52b8eebdf2880868b5 (patch)
tree444ec1e42073e30867c27806cdfdc5e149290a5e
parentbee4a4d361c054c531c3a27024f9ff3efef3635b (diff)
Properly dump dropped foreign table cols in binary-upgrade mode.
In binary upgrade mode, we need to recreate and then drop dropped columns so that all the columns get the right attribute number. This is true for foreign tables as well as for native tables. For foreign tables we have been getting the first part right but not the second, leading to bogus columns in the upgraded database. Fix this all the way back to 9.1, where foreign tables were introduced.
-rw-r--r--src/bin/pg_dump/pg_dump.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c
index 7b25e81020a..72f172bf1f3 100644
--- a/src/bin/pg_dump/pg_dump.c
+++ b/src/bin/pg_dump/pg_dump.c
@@ -12595,7 +12595,8 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
* attislocal correctly, plus fix up any inherited CHECK constraints.
* Analogously, we set up typed tables using ALTER TABLE / OF here.
*/
- if (binary_upgrade && tbinfo->relkind == RELKIND_RELATION)
+ if (binary_upgrade && (tbinfo->relkind == RELKIND_RELATION ||
+ tbinfo->relkind == RELKIND_FOREIGN_TABLE) )
{
for (j = 0; j < tbinfo->numatts; j++)
{
@@ -12613,8 +12614,13 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
appendStringLiteralAH(q, fmtId(tbinfo->dobj.name), fout);
appendPQExpBuffer(q, "::pg_catalog.regclass;\n");
- appendPQExpBuffer(q, "ALTER TABLE ONLY %s ",
- fmtId(tbinfo->dobj.name));
+ if (tbinfo->relkind == RELKIND_RELATION)
+ appendPQExpBuffer(q, "ALTER TABLE ONLY %s ",
+ fmtId(tbinfo->dobj.name));
+ else
+ appendPQExpBuffer(q, "ALTER FOREIGN TABLE %s ",
+ fmtId(tbinfo->dobj.name));
+
appendPQExpBuffer(q, "DROP COLUMN %s;\n",
fmtId(tbinfo->attnames[j]));
}