12
12
* by PostgreSQL
13
13
*
14
14
* IDENTIFICATION
15
- * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.417 2005/08/15 02:36:29 tgl Exp $
15
+ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.418 2005/08/15 21:50:15 tgl Exp $
16
16
*
17
17
*-------------------------------------------------------------------------
18
18
*/
@@ -2305,9 +2305,9 @@ getFuncs(int *numFuncs)
2305
2305
if (g_fout -> remoteVersion >= 70300 )
2306
2306
{
2307
2307
/*
2308
- * We now collect info on pg_catalog resident functions, but
2309
- * only if they are language call handlers or validators, and
2310
- * only for 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
+ * only if they are call handlers or validators for PL languages .
2311
2311
*/
2312
2312
appendPQExpBuffer (query ,
2313
2313
"SELECT tableoid, oid, proname, prolang, "
@@ -2316,10 +2316,10 @@ getFuncs(int *numFuncs)
2316
2316
"(%s proowner) as rolname, "
2317
2317
"CASE WHEN oid IN "
2318
2318
" (select lanplcallfoid from pg_language "
2319
- " where lanplcallfoid != 0 ) THEN true "
2319
+ " where lanispl ) THEN true "
2320
2320
" WHEN oid IN "
2321
2321
" (select lanvalidator from pg_language "
2322
- " where lanplcallfoid != 0 ) THEN true "
2322
+ " where lanispl ) THEN true "
2323
2323
" ELSE false END AS is_pl_handler "
2324
2324
"FROM pg_proc "
2325
2325
"WHERE NOT proisagg "
@@ -2328,10 +2328,10 @@ getFuncs(int *numFuncs)
2328
2328
" where nspname = 'pg_catalog')"
2329
2329
" OR oid IN "
2330
2330
" (select lanplcallfoid from pg_language "
2331
- " where lanplcallfoid != 0 ) "
2331
+ " where lanispl ) "
2332
2332
" OR oid IN "
2333
2333
" (select lanvalidator from pg_language "
2334
- " where lanplcallfoid != 0 ))" ,
2334
+ " where lanispl ))" ,
2335
2335
username_subquery );
2336
2336
}
2337
2337
else if (g_fout -> remoteVersion >= 70100 )
@@ -2402,7 +2402,7 @@ getFuncs(int *numFuncs)
2402
2402
finfo [i ].prorettype = atooid (PQgetvalue (res , i , i_prorettype ));
2403
2403
finfo [i ].proacl = strdup (PQgetvalue (res , i , i_proacl ));
2404
2404
finfo [i ].nargs = atoi (PQgetvalue (res , i , i_pronargs ));
2405
- finfo [i ].isProlangFunc =
2405
+ finfo [i ].islanghandler =
2406
2406
strcmp (PQgetvalue (res , i , i_is_pl_handler ), "t" ) == 0 ;
2407
2407
if (finfo [i ].nargs == 0 )
2408
2408
finfo [i ].argtypes = NULL ;
@@ -5095,6 +5095,29 @@ dumpCompositeType(Archive *fout, TypeInfo *tinfo)
5095
5095
destroyPQExpBuffer (query );
5096
5096
}
5097
5097
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
+
5098
5121
/*
5099
5122
* dumpProcLang
5100
5123
* writes out to fout the queries to recreate a user-defined
@@ -5113,28 +5136,33 @@ dumpProcLang(Archive *fout, ProcLangInfo *plang)
5113
5136
return ;
5114
5137
5115
5138
/*
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.
5122
5140
*/
5123
-
5124
5141
funcInfo = findFuncByOid (plang -> lanplcallfoid );
5125
5142
if (funcInfo == NULL )
5143
+ {
5144
+ write_msg (NULL , "WARNING: handler function for language \"%s\" not found\n" ,
5145
+ plang -> dobj .name );
5126
5146
return ;
5127
-
5128
- if (!funcInfo -> isProlangFunc && !funcInfo -> dobj .namespace -> dump )
5129
- return ;
5147
+ }
5130
5148
5131
5149
if (OidIsValid (plang -> lanvalidator ))
5132
5150
{
5133
5151
validatorInfo = findFuncByOid (plang -> lanvalidator );
5134
5152
if (validatorInfo == NULL )
5153
+ {
5154
+ write_msg (NULL , "WARNING: validator function for language \"%s\" not found\n" ,
5155
+ plang -> dobj .name );
5135
5156
return ;
5157
+ }
5136
5158
}
5137
5159
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
+
5138
5166
defqry = createPQExpBuffer ();
5139
5167
delqry = createPQExpBuffer ();
5140
5168
@@ -5160,6 +5188,11 @@ dumpProcLang(Archive *fout, ProcLangInfo *plang)
5160
5188
}
5161
5189
appendPQExpBuffer (defqry , ";\n" );
5162
5190
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
+ */
5163
5196
ArchiveEntry (fout , plang -> dobj .catId , plang -> dobj .dumpId ,
5164
5197
plang -> dobj .name ,
5165
5198
funcInfo -> dobj .namespace -> dobj .name , NULL , "" ,
@@ -5323,10 +5356,13 @@ dumpFunc(Archive *fout, FuncInfo *finfo)
5323
5356
char * * argmodes = NULL ;
5324
5357
char * * argnames = NULL ;
5325
5358
5326
- /* Dump only funcs in dumpable namespaces, or needed language handlers */
5327
- if ((!finfo -> isProlangFunc && !finfo -> dobj .namespace -> dump ) || dataOnly )
5359
+ if (dataOnly )
5328
5360
return ;
5329
5361
5362
+ /* Dump only funcs in dumpable namespaces, or needed language handlers */
5363
+ if (!finfo -> dobj .namespace -> dump &&
5364
+ (!finfo -> islanghandler || !shouldDumpProcLangs ()))
5365
+ return ;
5330
5366
5331
5367
query = createPQExpBuffer ();
5332
5368
q = createPQExpBuffer ();
0 commit comments