mirror of
https://github.com/postgres/postgres.git
synced 2025-09-08 00:47:37 +03:00
Backpatched changes for rules when casts are dumped according to
discussion on hackers. Jan
This commit is contained in:
@@ -22,7 +22,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.305.2.7 2003/06/25 04:09:15 momjian Exp $
|
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.305.2.8 2003/09/28 17:46:19 wieck Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@@ -3816,6 +3816,7 @@ dumpCasts(Archive *fout,
|
|||||||
PQExpBuffer query = createPQExpBuffer();
|
PQExpBuffer query = createPQExpBuffer();
|
||||||
PQExpBuffer defqry = createPQExpBuffer();
|
PQExpBuffer defqry = createPQExpBuffer();
|
||||||
PQExpBuffer delqry = createPQExpBuffer();
|
PQExpBuffer delqry = createPQExpBuffer();
|
||||||
|
PQExpBuffer castsig = createPQExpBuffer();
|
||||||
int ntups;
|
int ntups;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@@ -3845,16 +3846,51 @@ dumpCasts(Archive *fout,
|
|||||||
char *castcontext = PQgetvalue(res, i, 4);
|
char *castcontext = PQgetvalue(res, i, 4);
|
||||||
int fidx = -1;
|
int fidx = -1;
|
||||||
const char *((*deps)[]);
|
const char *((*deps)[]);
|
||||||
|
int source_idx;
|
||||||
|
int target_idx;
|
||||||
|
|
||||||
if (strcmp(castfunc, "0") != 0)
|
if (strcmp(castfunc, "0") != 0)
|
||||||
fidx = findFuncByOid(finfo, numFuncs, castfunc);
|
fidx = findFuncByOid(finfo, numFuncs, castfunc);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We treat the cast as being in the namespace of the underlying
|
* As per discussion we dump casts if one or more of the underlying
|
||||||
* function. This doesn't handle binary compatible casts. Where
|
* objects (the conversion function and the two data types) are not
|
||||||
* should those go?
|
* builtin AND if all of the non-builtin objects namespaces are
|
||||||
|
* included in the dump. Builtin meaning, the namespace name does
|
||||||
|
* not start with "pg_".
|
||||||
*/
|
*/
|
||||||
if (fidx < 0 || !finfo[fidx].pronamespace->dump)
|
source_idx = findTypeByOid(tinfo, numTypes, castsource);
|
||||||
|
target_idx = findTypeByOid(tinfo, numTypes, casttarget);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Skip this cast if all objects are from pg_
|
||||||
|
*/
|
||||||
|
if ((fidx < 0 || strncmp(finfo[fidx].pronamespace->nspname, "pg_", 3) == 0) &&
|
||||||
|
strncmp(tinfo[source_idx].typnamespace->nspname, "pg_", 3) == 0 &&
|
||||||
|
strncmp(tinfo[target_idx].typnamespace->nspname, "pg_", 3) == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Skip cast if function isn't from pg_ and that namespace is
|
||||||
|
* not dumped.
|
||||||
|
*/
|
||||||
|
if (fidx >= 0 &&
|
||||||
|
strncmp(finfo[fidx].pronamespace->nspname, "pg_", 3) != 0 &&
|
||||||
|
!finfo[fidx].pronamespace->dump)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Same for the Source type
|
||||||
|
*/
|
||||||
|
if (strncmp(tinfo[source_idx].typnamespace->nspname, "pg_", 3) != 0 &&
|
||||||
|
!tinfo[source_idx].typnamespace->dump)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* and the target type.
|
||||||
|
*/
|
||||||
|
if (strncmp(tinfo[target_idx].typnamespace->nspname, "pg_", 3) != 0 &&
|
||||||
|
!tinfo[target_idx].typnamespace->dump)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* Make a dependency to ensure function is dumped first */
|
/* Make a dependency to ensure function is dumped first */
|
||||||
@@ -3870,6 +3906,7 @@ dumpCasts(Archive *fout,
|
|||||||
|
|
||||||
resetPQExpBuffer(defqry);
|
resetPQExpBuffer(defqry);
|
||||||
resetPQExpBuffer(delqry);
|
resetPQExpBuffer(delqry);
|
||||||
|
resetPQExpBuffer(castsig);
|
||||||
|
|
||||||
appendPQExpBuffer(delqry, "DROP CAST (%s AS %s);\n",
|
appendPQExpBuffer(delqry, "DROP CAST (%s AS %s);\n",
|
||||||
getFormattedTypeName(castsource, zeroAsNone),
|
getFormattedTypeName(castsource, zeroAsNone),
|
||||||
@@ -3891,9 +3928,13 @@ dumpCasts(Archive *fout,
|
|||||||
appendPQExpBuffer(defqry, " AS IMPLICIT");
|
appendPQExpBuffer(defqry, " AS IMPLICIT");
|
||||||
appendPQExpBuffer(defqry, ";\n");
|
appendPQExpBuffer(defqry, ";\n");
|
||||||
|
|
||||||
|
appendPQExpBuffer(castsig, "CAST (%s AS %s)",
|
||||||
|
getFormattedTypeName(castsource, zeroAsNone),
|
||||||
|
getFormattedTypeName(casttarget, zeroAsNone));
|
||||||
|
|
||||||
ArchiveEntry(fout, castoid,
|
ArchiveEntry(fout, castoid,
|
||||||
format_function_signature(&finfo[fidx], false),
|
castsig->data,
|
||||||
finfo[fidx].pronamespace->nspname, "",
|
tinfo[source_idx].typnamespace->nspname, "",
|
||||||
"CAST", deps,
|
"CAST", deps,
|
||||||
defqry->data, delqry->data,
|
defqry->data, delqry->data,
|
||||||
NULL, NULL, NULL);
|
NULL, NULL, NULL);
|
||||||
@@ -3904,6 +3945,7 @@ dumpCasts(Archive *fout,
|
|||||||
destroyPQExpBuffer(query);
|
destroyPQExpBuffer(query);
|
||||||
destroyPQExpBuffer(defqry);
|
destroyPQExpBuffer(defqry);
|
||||||
destroyPQExpBuffer(delqry);
|
destroyPQExpBuffer(delqry);
|
||||||
|
destroyPQExpBuffer(castsig);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user