Skip to content

Commit a6790ce

Browse files
Jan WieckJan Wieck
Jan Wieck
authored and
Jan Wieck
committed
Changed the logic when a CAST is dumped according to discussion
on pgsql-hackers. A cast is included in the dump output if any of the objects does not belong to a system namespace and all of the non-system namespace objects belong to dumped namespaces. System namespace is defined as nspname begins with "pg_". Jan
1 parent 227dd9b commit a6790ce

File tree

1 file changed

+49
-7
lines changed

1 file changed

+49
-7
lines changed

src/bin/pg_dump/pg_dump.c

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* by PostgreSQL
1313
*
1414
* IDENTIFICATION
15-
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.350 2003/09/23 23:31:52 tgl Exp $
15+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.351 2003/09/27 15:34:06 wieck Exp $
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
@@ -3903,6 +3903,7 @@ dumpCasts(Archive *fout,
39033903
PQExpBuffer query = createPQExpBuffer();
39043904
PQExpBuffer defqry = createPQExpBuffer();
39053905
PQExpBuffer delqry = createPQExpBuffer();
3906+
PQExpBuffer castsig = createPQExpBuffer();
39063907
int ntups;
39073908
int i;
39083909

@@ -3932,16 +3933,51 @@ dumpCasts(Archive *fout,
39323933
char *castcontext = PQgetvalue(res, i, 4);
39333934
int fidx = -1;
39343935
const char *((*deps)[]);
3936+
int source_idx;
3937+
int target_idx;
39353938

39363939
if (strcmp(castfunc, "0") != 0)
39373940
fidx = findFuncByOid(finfo, numFuncs, castfunc);
39383941

39393942
/*
3940-
* We treat the cast as being in the namespace of the underlying
3941-
* function. This doesn't handle binary compatible casts. Where
3942-
* should those go?
3943+
* As per discussion we dump casts if one or more of the underlying
3944+
* objects (the conversion function and the two data types) are not
3945+
* builtin AND if all of the non-builtin objects namespaces are
3946+
* included in the dump. Builtin meaning, the namespace name does
3947+
* not start with "pg_".
39433948
*/
3944-
if (fidx < 0 || !finfo[fidx].pronamespace->dump)
3949+
source_idx = findTypeByOid(tinfo, numTypes, castsource);
3950+
target_idx = findTypeByOid(tinfo, numTypes, casttarget);
3951+
3952+
/*
3953+
* Skip this cast if all objects are from pg_
3954+
*/
3955+
if ((fidx < 0 || strncmp(finfo[fidx].pronamespace->nspname, "pg_", 3) == 0) &&
3956+
strncmp(tinfo[source_idx].typnamespace->nspname, "pg_", 3) == 0 &&
3957+
strncmp(tinfo[target_idx].typnamespace->nspname, "pg_", 3) == 0)
3958+
continue;
3959+
3960+
/*
3961+
* Skip cast if function isn't from pg_ and that namespace is
3962+
* not dumped.
3963+
*/
3964+
if (fidx >= 0 &&
3965+
strncmp(finfo[fidx].pronamespace->nspname, "pg_", 3) != 0 &&
3966+
!finfo[fidx].pronamespace->dump)
3967+
continue;
3968+
3969+
/*
3970+
* Same for the Source type
3971+
*/
3972+
if (strncmp(tinfo[source_idx].typnamespace->nspname, "pg_", 3) != 0 &&
3973+
!tinfo[source_idx].typnamespace->dump)
3974+
continue;
3975+
3976+
/*
3977+
* and the target type.
3978+
*/
3979+
if (strncmp(tinfo[target_idx].typnamespace->nspname, "pg_", 3) != 0 &&
3980+
!tinfo[target_idx].typnamespace->dump)
39453981
continue;
39463982

39473983
/* Make a dependency to ensure function is dumped first */
@@ -3957,6 +3993,7 @@ dumpCasts(Archive *fout,
39573993

39583994
resetPQExpBuffer(defqry);
39593995
resetPQExpBuffer(delqry);
3996+
resetPQExpBuffer(castsig);
39603997

39613998
appendPQExpBuffer(delqry, "DROP CAST (%s AS %s);\n",
39623999
getFormattedTypeName(castsource, zeroAsNone),
@@ -3978,9 +4015,13 @@ dumpCasts(Archive *fout,
39784015
appendPQExpBuffer(defqry, " AS IMPLICIT");
39794016
appendPQExpBuffer(defqry, ";\n");
39804017

4018+
appendPQExpBuffer(castsig, "CAST (%s AS %s)",
4019+
getFormattedTypeName(castsource, zeroAsNone),
4020+
getFormattedTypeName(casttarget, zeroAsNone));
4021+
39814022
ArchiveEntry(fout, castoid,
3982-
format_function_signature(&finfo[fidx], false),
3983-
finfo[fidx].pronamespace->nspname, "",
4023+
castsig->data,
4024+
tinfo[source_idx].typnamespace->nspname, "",
39844025
"CAST", deps,
39854026
defqry->data, delqry->data,
39864027
NULL, NULL, NULL);
@@ -3991,6 +4032,7 @@ dumpCasts(Archive *fout,
39914032
destroyPQExpBuffer(query);
39924033
destroyPQExpBuffer(defqry);
39934034
destroyPQExpBuffer(delqry);
4035+
destroyPQExpBuffer(castsig);
39944036
}
39954037

39964038

0 commit comments

Comments
 (0)