Skip to content

Commit b246207

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 d1e25b7 commit b246207

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
@@ -125,7 +125,7 @@ getSchemaData(int *numTablesPtr)
125125
funinfo = getFuncs(&numFuncs);
126126
funinfoindex = buildIndexArray(funinfo, numFuncs, sizeof(FuncInfo));
127127

128-
/* this must be after getFuncs */
128+
/* this must be after getTables and getFuncs */
129129
if (g_verbose)
130130
write_msg(NULL, "reading user-defined types\n");
131131
typinfo = getTypes(&numTypes);

src/bin/pg_dump/pg_dump.c

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,8 +1093,11 @@ selectDumpableTable(TableInfo *tbinfo)
10931093
* If it's a table's rowtype or an autogenerated array type, we also apply a
10941094
* special type code to facilitate sorting into the desired order. (We don't
10951095
* want to consider those to be ordinary types because that would bring tables
1096-
* up into the datatype part of the dump order.) Those tests should be made
1097-
* first to ensure the objType change is applied regardless of namespace etc.
1096+
* up into the datatype part of the dump order.) We still set the object's
1097+
* dump flag; that's not going to cause the dummy type to be dumped, but we
1098+
* need it so that casts involving such types will be dumped correctly -- see
1099+
* dumpCast. This means the flag should be set the same as for the underlying
1100+
* object (the table or base type).
10981101
*/
10991102
static void
11001103
selectDumpableType(TypeInfo *tyinfo)
@@ -1103,19 +1106,30 @@ selectDumpableType(TypeInfo *tyinfo)
11031106
if (OidIsValid(tyinfo->typrelid) &&
11041107
tyinfo->typrelkind != RELKIND_COMPOSITE_TYPE)
11051108
{
1106-
tyinfo->dobj.dump = false;
1109+
TableInfo *tytable = findTableByOid(tyinfo->typrelid);
1110+
11071111
tyinfo->dobj.objType = DO_DUMMY_TYPE;
1112+
if (tytable != NULL)
1113+
tyinfo->dobj.dump = tytable->dobj.dump;
1114+
else
1115+
tyinfo->dobj.dump = false;
1116+
return;
11081117
}
11091118

11101119
/* skip auto-generated array types */
1111-
else if (tyinfo->isArray)
1120+
if (tyinfo->isArray)
11121121
{
1113-
tyinfo->dobj.dump = false;
11141122
tyinfo->dobj.objType = DO_DUMMY_TYPE;
1123+
/*
1124+
* Fall through to set the dump flag; we assume that the subsequent
1125+
* rules will do the same thing as they would for the array's base
1126+
* type. (We cannot reliably look up the base type here, since
1127+
* getTypes may not have processed it yet.)
1128+
*/
11151129
}
11161130

11171131
/* dump only types in dumpable namespaces */
1118-
else if (!tyinfo->dobj.namespace->dobj.dump)
1132+
if (!tyinfo->dobj.namespace->dobj.dump)
11191133
tyinfo->dobj.dump = false;
11201134

11211135
/* skip undefined placeholder types */

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy