12
12
*by PostgreSQL
13
13
*
14
14
* 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 $
16
16
*
17
17
*-------------------------------------------------------------------------
18
18
*/
@@ -3903,6 +3903,7 @@ dumpCasts(Archive *fout,
3903
3903
PQExpBuffer query = createPQExpBuffer ();
3904
3904
PQExpBuffer defqry = createPQExpBuffer ();
3905
3905
PQExpBuffer delqry = createPQExpBuffer ();
3906
+ PQExpBuffer castsig = createPQExpBuffer ();
3906
3907
int ntups ;
3907
3908
int i ;
3908
3909
@@ -3932,16 +3933,51 @@ dumpCasts(Archive *fout,
3932
3933
char * castcontext = PQgetvalue (res ,i ,4 );
3933
3934
int fidx = -1 ;
3934
3935
const char * ((* deps )[]);
3936
+ int source_idx ;
3937
+ int target_idx ;
3935
3938
3936
3939
if (strcmp (castfunc ,"0" )!= 0 )
3937
3940
fidx = findFuncByOid (finfo ,numFuncs ,castfunc );
3938
3941
3939
3942
/*
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_".
3943
3948
*/
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 )
3945
3981
continue ;
3946
3982
3947
3983
/* Make a dependency to ensure function is dumped first */
@@ -3957,6 +3993,7 @@ dumpCasts(Archive *fout,
3957
3993
3958
3994
resetPQExpBuffer (defqry );
3959
3995
resetPQExpBuffer (delqry );
3996
+ resetPQExpBuffer (castsig );
3960
3997
3961
3998
appendPQExpBuffer (delqry ,"DROP CAST (%s AS %s);\n" ,
3962
3999
getFormattedTypeName (castsource ,zeroAsNone ),
@@ -3978,9 +4015,13 @@ dumpCasts(Archive *fout,
3978
4015
appendPQExpBuffer (defqry ," AS IMPLICIT" );
3979
4016
appendPQExpBuffer (defqry ,";\n" );
3980
4017
4018
+ appendPQExpBuffer (castsig ,"CAST (%s AS %s)" ,
4019
+ getFormattedTypeName (castsource ,zeroAsNone ),
4020
+ getFormattedTypeName (casttarget ,zeroAsNone ));
4021
+
3981
4022
ArchiveEntry (fout ,castoid ,
3982
- format_function_signature ( & finfo [ fidx ], false) ,
3983
- finfo [ fidx ]. pronamespace -> nspname ,"" ,
4023
+ castsig -> data ,
4024
+ tinfo [ source_idx ]. typnamespace -> nspname ,"" ,
3984
4025
"CAST" ,deps ,
3985
4026
defqry -> data ,delqry -> data ,
3986
4027
NULL ,NULL ,NULL );
@@ -3991,6 +4032,7 @@ dumpCasts(Archive *fout,
3991
4032
destroyPQExpBuffer (query );
3992
4033
destroyPQExpBuffer (defqry );
3993
4034
destroyPQExpBuffer (delqry );
4035
+ destroyPQExpBuffer (castsig );
3994
4036
}
3995
4037
3996
4038