]> granicus.if.org Git - postgresql/commitdiff
Fix binary upgrade of altered typed tables
authorPeter Eisentraut <peter_e@gmx.net>
Wed, 27 Apr 2011 19:08:22 +0000 (22:08 +0300)
committerPeter Eisentraut <peter_e@gmx.net>
Wed, 27 Apr 2011 19:11:09 +0000 (22:11 +0300)
Instead of dumping them as CREATE TABLE ... OF, dump them as normal
tables with the usual special processing for dropped columns, and then
attach them to the type afterward, using ALTER TABLE ... OF.  This is
analogous to the existing handling of inherited tables.

src/bin/pg_dump/pg_dump.c

index c2f6180e99974c1bb909fd0557ee1a2d55aaa212..afc7fd7032a876e09fdaf3a02a50d861f0d82f5e 100644 (file)
@@ -12004,7 +12004,11 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
                                                  "UNLOGGED " : "",
                                                  reltypename,
                                                  fmtId(tbinfo->dobj.name));
-               if (tbinfo->reloftype)
+               /*
+                * In case of a binary upgrade, we dump the table normally and attach
+                * it to the type afterward.
+                */
+               if (tbinfo->reloftype && !binary_upgrade)
                        appendPQExpBuffer(q, " OF %s", tbinfo->reloftype);
                actual_atts = 0;
                for (j = 0; j < tbinfo->numatts; j++)
@@ -12032,7 +12036,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
                                bool            has_notnull = (tbinfo->notnull[j]
                                                          && (!tbinfo->inhNotNull[j] || binary_upgrade));
 
-                               if (tbinfo->reloftype && !has_default && !has_notnull)
+                               if (tbinfo->reloftype && !has_default && !has_notnull && !binary_upgrade)
                                        continue;
 
                                /* Format properly if not first attr */
@@ -12060,7 +12064,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
                                }
 
                                /* Attribute type */
-                               if (tbinfo->reloftype)
+                               if (tbinfo->reloftype && !binary_upgrade)
                                {
                                        appendPQExpBuffer(q, "WITH OPTIONS");
                                }
@@ -12126,7 +12130,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
 
                if (actual_atts)
                        appendPQExpBuffer(q, "\n)");
-               else if (!tbinfo->reloftype)
+               else if (!(tbinfo->reloftype && !binary_upgrade))
                {
                        /*
                         * We must have a parenthesized attribute list, even though empty,
@@ -12192,6 +12196,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
                 * an INHERITS clause --- the latter would possibly mess up the column
                 * order.  That also means we have to take care about setting
                 * 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)
                {
@@ -12268,6 +12273,14 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
                                }
                        }
 
+                       if (tbinfo->reloftype)
+                       {
+                               appendPQExpBuffer(q, "\n-- For binary upgrade, set up typed tables this way.\n");
+                               appendPQExpBuffer(q, "ALTER TABLE ONLY %s OF %s;\n",
+                                                                 fmtId(tbinfo->dobj.name),
+                                                                 tbinfo->reloftype);
+                       }
+
                        appendPQExpBuffer(q, "\n-- For binary upgrade, set heap's relfrozenxid\n");
                        appendPQExpBuffer(q, "UPDATE pg_catalog.pg_class\n"
                                                          "SET relfrozenxid = '%u'\n"