8000 Fix pg_dump to dump casts between auto-generated types. · fschopp/postgres@58625e4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 58625e4

Browse files
committed
Fix pg_dump to dump casts between auto-generated types.
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.
1 parent 6d363e0 commit 58625e4

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

src/bin/pg_dump/common.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ getSchemaData(int *numTablesPtr)
129129
funinfo = getFuncs(&numFuncs);
130130
funinfoindex = buildIndexArray(funinfo, numFuncs, sizeof(FuncInfo));
131131

132-
/* this must be after getFuncs */
132+
/* this must be after getTables and getFuncs */
133133
if (g_verbose)
134134
write_msg(NULL, "reading user-defined types\n");
135135
typinfo = getTypes(&numTypes);

src/bin/pg_dump/pg_dump.c

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,8 +1013,11 @@ selectDumpableTable(TableInfo *tbinfo)
10131013
* If it's a table's rowtype or an autogenerated array type, we also apply a
10141014
* special type code to facilitate sorting into the desired order. (We don't
10151015
* want to consider those to be ordinary types because that would bring tables
1016-
* up into the datatype part of the dump order.) Those tests should be made
1017-
* first to ensure the objType change is applied regardless of namespace etc.
1016+
* up into the datatype part of the dump order.) We still set the object's
1017+
* dump flag; that's not going to cause the dummy type to be dumped, but we
1018+
* need it so that casts involving such types will be dumped correctly -- see
1019+
* dumpCast. This means the flag should be set the same as for the underlying
1020+
* object (the table or base type).
10181021
*/
10191022
static void
10201023
selectDumpableType(TypeInfo *tinfo)
@@ -1023,19 +1026,30 @@ selectDumpableType(TypeInfo *tinfo)
10231026
if (OidIsValid(tinfo->typrelid) &&
10241027
tinfo->typrelkind != RELKIND_COMPOSITE_TYPE)
10251028
{
1026-
tinfo->dobj.dump = false;
1029+
TableInfo *tytable = findTableByOid(tinfo->typrelid);
1030+
10271031
tinfo->dobj.objType = DO_DUMMY_TYPE;
1032+
if (tytable != NULL)
1033+
tinfo->dobj.dump = tytable->dobj.dump;
1034+
else
1035+
tinfo->dobj.dump = false;
1036+
return;
10281037
}
10291038

10301039
/* skip auto-generated array types */
1031-
else if (tinfo->isArray)
1040+
if (tinfo->isArray)
10321041
{
1033-
tinfo->dobj.dump = false;
10341042
tinfo->dobj.objType = DO_DUMMY_TYPE;
1043+
/*
1044+
* Fall through to set the dump flag; we assume that the subsequent
1045+
* rules will do the same thing as they would for the array's base
1046+
* type. (We cannot reliably look up the base type here, since
1047+
* getTypes may not have processed it yet.)
1048+
*/
10351049
}
10361050

10371051
/* dump only types in dumpable namespaces */
1038-
else if (!tinfo->dobj.namespace->dobj.dump)
1052+
if (!tinfo->dobj.namespace->dobj.dump)
10391053
tinfo->dobj.dump = false;
10401054

10411055
/* skip undefined placeholder types */

0 commit comments

Comments
 (0)
0