]> granicus.if.org Git - postgresql/commitdiff
Properly dump dropped foreign table cols in binary-upgrade mode.
authorAndrew Dunstan <andrew@dunslane.net>
Tue, 25 Jun 2013 17:44:34 +0000 (13:44 -0400)
committerAndrew Dunstan <andrew@dunslane.net>
Tue, 25 Jun 2013 17:44:34 +0000 (13:44 -0400)
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.

src/bin/pg_dump/pg_dump.c

index 6459e636d12bf6f91a16e8d425f1e1a27ef9cec1..f4c855485bff94fc7b11fe767878946ea57b3086 100644 (file)
@@ -12440,7 +12440,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++)
                        {
@@ -12458,8 +12459,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]));
                                }