]> granicus.if.org Git - postgresql/commitdiff
Fix pg_dump to dump casts between auto-generated types.
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 18 Oct 2011 21:11:18 +0000 (17:11 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 18 Oct 2011 21:11:18 +0000 (17:11 -0400)
The heuristic for when to dump a cast failed for a cast between table
rowtypes, as reported by Frédéric Rejol.  Fix it by setting
the "dump" flag for such a type the same way as the flag is set for the
underlying table or base type.  This won't result in the auto-generated
type appearing in the output, since setting its objType to DO_DUMMY_TYPE
unconditionally suppresses that.  But it will result in dumpCast doing what
was intended.

Back-patch to 8.3.  The 8.2 code is rather different in this area, and it
doesn't seem worth any risk to fix a corner case that nobody has stumbled
on before.

src/bin/pg_dump/common.c
src/bin/pg_dump/pg_dump.c

index 54a27bee3e8f6a3ae2bb75ba00b12d97f8e6ed89..814fee177a260c3fcc4fdd1176ca4d62ea443d4e 100644 (file)
@@ -127,7 +127,7 @@ getSchemaData(int *numTablesPtr)
        funinfo = getFuncs(&numFuncs);
        funinfoindex = buildIndexArray(funinfo, numFuncs, sizeof(FuncInfo));
 
-       /* this must be after getFuncs */
+       /* this must be after getTables and getFuncs */
        if (g_verbose)
                write_msg(NULL, "reading user-defined types\n");
        typinfo = getTypes(&numTypes);
index 14e1aec52e5943e547d62789f0a6bb1f6ff165eb..a3a30e44cdb970c950987499e5f60914ffab338a 100644 (file)
@@ -957,8 +957,11 @@ selectDumpableTable(TableInfo *tbinfo)
  * If it's a table's rowtype or an autogenerated array type, we also apply a
  * special type code to facilitate sorting into the desired order.  (We don't
  * want to consider those to be ordinary types because that would bring tables
- * up into the datatype part of the dump order.)  Those tests should be made
- * first to ensure the objType change is applied regardless of namespace etc.
+ * up into the datatype part of the dump order.)  We still set the object's
+ * dump flag; that's not going to cause the dummy type to be dumped, but we
+ * need it so that casts involving such types will be dumped correctly -- see
+ * dumpCast.  This means the flag should be set the same as for the underlying
+ * object (the table or base type).
  */
 static void
 selectDumpableType(TypeInfo *tinfo)
@@ -967,19 +970,30 @@ selectDumpableType(TypeInfo *tinfo)
        if (OidIsValid(tinfo->typrelid) &&
                tinfo->typrelkind != RELKIND_COMPOSITE_TYPE)
        {
-               tinfo->dobj.dump = false;
+               TableInfo  *tytable = findTableByOid(tinfo->typrelid);
+
                tinfo->dobj.objType = DO_DUMMY_TYPE;
+               if (tytable != NULL)
+                       tinfo->dobj.dump = tytable->dobj.dump;
+               else
+                       tinfo->dobj.dump = false;
+               return;
        }
 
        /* skip auto-generated array types */
-       else if (tinfo->isArray)
+       if (tinfo->isArray)
        {
-               tinfo->dobj.dump = false;
                tinfo->dobj.objType = DO_DUMMY_TYPE;
+               /*
+                * Fall through to set the dump flag; we assume that the subsequent
+                * rules will do the same thing as they would for the array's base
+                * type.  (We cannot reliably look up the base type here, since
+                * getTypes may not have processed it yet.)
+                */
        }
 
        /* dump only types in dumpable namespaces */
-       else if (!tinfo->dobj.namespace->dobj.dump)
+       if (!tinfo->dobj.namespace->dobj.dump)
                tinfo->dobj.dump = false;
 
        /* skip undefined placeholder types */