1212 *by PostgreSQL
1313 *
1414 * IDENTIFICATION
15- * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.502 2008/09/24 19:33:15 heikki Exp $
15+ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.503 2008/10/31 08:39:21 heikki Exp $
1616 *
1717 *-------------------------------------------------------------------------
1818 */
@@ -36,6 +36,7 @@ intoptreset;
3636
3737#include "access/attnum.h"
3838#include "access/sysattr.h"
39+ #include "catalog/pg_cast.h"
3940#include "catalog/pg_class.h"
4041#include "catalog/pg_proc.h"
4142#include "catalog/pg_trigger.h"
@@ -4410,21 +4411,31 @@ getCasts(int *numCasts)
44104411int i_casttarget ;
44114412int i_castfunc ;
44124413int i_castcontext ;
4414+ int i_castmethod ;
44134415
44144416/* Make sure we are in proper schema */
44154417selectSourceSchema ("pg_catalog" );
44164418
4417- if (g_fout -> remoteVersion >=70300 )
4419+ if (g_fout -> remoteVersion >=80400 )
4420+ {
4421+ appendPQExpBuffer (query ,"SELECT tableoid, oid, "
4422+ "castsource, casttarget, castfunc, castcontext, "
4423+ "castmethod "
4424+ "FROM pg_cast ORDER BY 3,4" );
4425+ }
4426+ else if (g_fout -> remoteVersion >=70300 )
44184427{
44194428appendPQExpBuffer (query ,"SELECT tableoid, oid, "
4420- "castsource, casttarget, castfunc, castcontext "
4429+ "castsource, casttarget, castfunc, castcontext, "
4430+ "CASE WHEN castfunc = 0 THEN 'b' ELSE 'f' END AS castmethod "
44214431"FROM pg_cast ORDER BY 3,4" );
44224432}
44234433else
44244434{
44254435appendPQExpBuffer (query ,"SELECT 0 as tableoid, p.oid, "
44264436"t1.oid as castsource, t2.oid as casttarget, "
4427- "p.oid as castfunc, 'e' as castcontext "
4437+ "p.oid as castfunc, 'e' as castcontext, "
4438+ "'f' as castmethod "
44284439"FROM pg_type t1, pg_type t2, pg_proc p "
44294440"WHERE p.pronargs = 1 AND "
44304441"p.proargtypes[0] = t1.oid AND "
@@ -4447,6 +4458,7 @@ getCasts(int *numCasts)
44474458i_casttarget = PQfnumber (res ,"casttarget" );
44484459i_castfunc = PQfnumber (res ,"castfunc" );
44494460i_castcontext = PQfnumber (res ,"castcontext" );
4461+ i_castmethod = PQfnumber (res ,"castmethod" );
44504462
44514463for (i = 0 ;i < ntups ;i ++ )
44524464{
@@ -4462,6 +4474,7 @@ getCasts(int *numCasts)
44624474castinfo [i ].casttarget = atooid (PQgetvalue (res ,i ,i_casttarget ));
44634475castinfo [i ].castfunc = atooid (PQgetvalue (res ,i ,i_castfunc ));
44644476castinfo [i ].castcontext = * (PQgetvalue (res ,i ,i_castcontext ));
4477+ castinfo [i ].castmethod = * (PQgetvalue (res ,i ,i_castmethod ));
44654478
44664479/*
44674480 * Try to name cast as concatenation of typnames. This is only used
@@ -7188,18 +7201,26 @@ dumpCast(Archive *fout, CastInfo *cast)
71887201getFormattedTypeName (cast -> castsource ,zeroAsNone ),
71897202getFormattedTypeName (cast -> casttarget ,zeroAsNone ));
71907203
7191- if (!OidIsValid (cast -> castfunc ))
7192- appendPQExpBuffer (defqry ,"WITHOUT FUNCTION" );
7193- else
7204+ switch (cast -> castmethod )
71947205{
7195- /*
7196- * Always qualify the function name, in case it is not in pg_catalog
7197- * schema (format_function_signature won't qualify it).
7198- */
7199- appendPQExpBuffer (defqry ,"WITH FUNCTION %s." ,
7200- fmtId (funcInfo -> dobj .namespace -> dobj .name ));
7201- appendPQExpBuffer (defqry ,"%s" ,
7202- format_function_signature (funcInfo , true));
7206+ case COERCION_METHOD_BINARY :
7207+ appendPQExpBuffer (defqry ,"WITHOUT FUNCTION" );
7208+ break ;
7209+ case COERCION_METHOD_INOUT :
7210+ appendPQExpBuffer (defqry ,"WITH INOUT" );
7211+ break ;
7212+ case COERCION_METHOD_FUNCTION :
7213+ /*
7214+ * Always qualify the function name, in case it is not in
7215+ * pg_catalog schema (format_function_signature won't qualify it).
7216+ */
7217+ appendPQExpBuffer (defqry ,"WITH FUNCTION %s." ,
7218+ fmtId (funcInfo -> dobj .namespace -> dobj .name ));
7219+ appendPQExpBuffer (defqry ,"%s" ,
7220+ format_function_signature (funcInfo , true));
7221+ break ;
7222+ default :
7223+ write_msg (NULL ,"WARNING: bogus value in pg_cast.castmethod field\n" );
72037224}
72047225
72057226if (cast -> castcontext == 'a' )