1212 *by PostgreSQL
1313 *
1414 * IDENTIFICATION
15- * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.417 2005/08/1502:36:29 tgl Exp $
15+ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.418 2005/08/1521:50:15 tgl Exp $
1616 *
1717 *-------------------------------------------------------------------------
1818 */
@@ -2305,9 +2305,9 @@ getFuncs(int *numFuncs)
23052305if (g_fout -> remoteVersion >=70300 )
23062306{
23072307/*
2308- *We now collect info on pg_catalog resident functions, but
2309- *only if they are language call handlers or validators, and
2310- * onlyfor non-default languages (i.e. not internal/C/SQL) .
2308+ *For 7.3 and up, we consider it's user-defined if it's not in
2309+ *pg_catalog. We also collect info on functions in pg_catalog, but
2310+ * onlyif they are call handlers or validators for PL languages .
23112311 */
23122312appendPQExpBuffer (query ,
23132313"SELECT tableoid, oid, proname, prolang, "
@@ -2316,10 +2316,10 @@ getFuncs(int *numFuncs)
23162316"(%s proowner) as rolname, "
23172317"CASE WHEN oid IN "
23182318" (select lanplcallfoid from pg_language "
2319- " wherelanplcallfoid != 0 ) THEN true "
2319+ " wherelanispl ) THEN true "
23202320" WHEN oid IN "
23212321" (select lanvalidator from pg_language "
2322- " wherelanplcallfoid != 0 ) THEN true "
2322+ " wherelanispl ) THEN true "
23232323" ELSE false END AS is_pl_handler "
23242324"FROM pg_proc "
23252325"WHERE NOT proisagg "
@@ -2328,10 +2328,10 @@ getFuncs(int *numFuncs)
23282328" where nspname = 'pg_catalog')"
23292329" OR oid IN "
23302330" (select lanplcallfoid from pg_language "
2331- " wherelanplcallfoid != 0 ) "
2331+ " wherelanispl ) "
23322332" OR oid IN "
23332333" (select lanvalidator from pg_language "
2334- " wherelanplcallfoid != 0 ))" ,
2334+ " wherelanispl ))" ,
23352335username_subquery );
23362336}
23372337else if (g_fout -> remoteVersion >=70100 )
@@ -2402,7 +2402,7 @@ getFuncs(int *numFuncs)
24022402finfo [i ].prorettype = atooid (PQgetvalue (res ,i ,i_prorettype ));
24032403finfo [i ].proacl = strdup (PQgetvalue (res ,i ,i_proacl ));
24042404finfo [i ].nargs = atoi (PQgetvalue (res ,i ,i_pronargs ));
2405- finfo [i ].isProlangFunc =
2405+ finfo [i ].islanghandler =
24062406strcmp (PQgetvalue (res ,i ,i_is_pl_handler ),"t" )== 0 ;
24072407if (finfo [i ].nargs == 0 )
24082408finfo [i ].argtypes = NULL ;
@@ -5095,6 +5095,29 @@ dumpCompositeType(Archive *fout, TypeInfo *tinfo)
50955095destroyPQExpBuffer (query );
50965096}
50975097
5098+ /*
5099+ * Determine whether we want to dump definitions for procedural languages.
5100+ * Since the languages themselves don't have schemas, we can't rely on
5101+ * the normal schema-based selection mechanism. We choose to dump them
5102+ * whenever neither --schema nor --table was given. (Before 8.1, we used
5103+ * the dump flag of the PL's call handler function, but in 8.1 this will
5104+ * probably always be false since call handlers are created in pg_catalog.)
5105+ *
5106+ * For some backwards compatibility with the older behavior, we forcibly
5107+ * dump a PL if its handler function (and validator if any) are in a
5108+ * dumpable namespace. That case is not checked here.
5109+ */
5110+ static bool
5111+ shouldDumpProcLangs (void )
5112+ {
5113+ if (selectTableName != NULL || selectSchemaName != NULL )
5114+ return false;
5115+ /* And they're schema not data */
5116+ if (dataOnly )
5117+ return false;
5118+ return true;
5119+ }
5120+
50985121/*
50995122 * dumpProcLang
51005123 * writes out to fout the queries to recreate a user-defined
@@ -5113,28 +5136,33 @@ dumpProcLang(Archive *fout, ProcLangInfo *plang)
51135136return ;
51145137
51155138/*
5116- * We dump PLs iff their underlying call handler functions have been
5117- * marked as language functions (or have a non-system OID in
5118- * pre-7.3 databases).We treat the PL itself as being in
5119- * the underlying function's namespace, though it isn't really. This
5120- * avoids searchpath problems for the HANDLER clause.
5121- *
5139+ * Find the support functions, complaining if not there.
51225140 */
5123-
51245141funcInfo = findFuncByOid (plang -> lanplcallfoid );
51255142if (funcInfo == NULL )
5143+ {
5144+ write_msg (NULL ,"WARNING: handler function for language \"%s\" not found\n" ,
5145+ plang -> dobj .name );
51265146return ;
5127-
5128- if (!funcInfo -> isProlangFunc && !funcInfo -> dobj .namespace -> dump )
5129- return ;
5147+ }
51305148
51315149if (OidIsValid (plang -> lanvalidator ))
51325150{
51335151validatorInfo = findFuncByOid (plang -> lanvalidator );
51345152if (validatorInfo == NULL )
5153+ {
5154+ write_msg (NULL ,"WARNING: validator function for language \"%s\" not found\n" ,
5155+ plang -> dobj .name );
51355156return ;
5157+ }
51365158}
51375159
5160+ /* Dump if we should, or if both support functions are dumpable */
5161+ if (!shouldDumpProcLangs ()&&
5162+ !(funcInfo -> dobj .namespace -> dump &&
5163+ (validatorInfo == NULL || validatorInfo -> dobj .namespace -> dump )))
5164+ return ;
5165+
51385166defqry = createPQExpBuffer ();
51395167delqry = createPQExpBuffer ();
51405168
@@ -5160,6 +5188,11 @@ dumpProcLang(Archive *fout, ProcLangInfo *plang)
51605188}
51615189appendPQExpBuffer (defqry ,";\n" );
51625190
5191+ /*
5192+ * We mark the PL's archive entry as being in the call handler's
5193+ * namespace; this is what makes it OK to refer to the handler with
5194+ * an unqualified name above.
5195+ */
51635196ArchiveEntry (fout ,plang -> dobj .catId ,plang -> dobj .dumpId ,
51645197plang -> dobj .name ,
51655198funcInfo -> dobj .namespace -> dobj .name ,NULL ,"" ,
@@ -5323,10 +5356,13 @@ dumpFunc(Archive *fout, FuncInfo *finfo)
53235356char * * argmodes = NULL ;
53245357char * * argnames = NULL ;
53255358
5326- /* Dump only funcs in dumpable namespaces, or needed language handlers */
5327- if ((!finfo -> isProlangFunc && !finfo -> dobj .namespace -> dump )|| dataOnly )
5359+ if (dataOnly )
53285360return ;
53295361
5362+ /* Dump only funcs in dumpable namespaces, or needed language handlers */
5363+ if (!finfo -> dobj .namespace -> dump &&
5364+ (!finfo -> islanghandler || !shouldDumpProcLangs ()))
5365+ return ;
53305366
53315367query = createPQExpBuffer ();
53325368q = createPQExpBuffer ();