|
7 | 7 | *
|
8 | 8 | *
|
9 | 9 | * IDENTIFICATION
|
10 |
| - * $Header: /cvsroot/pgsql/src/backend/catalog/pg_proc.c,v 1.26 1999/02/21 03:48:32 scrappy Exp $ |
| 10 | + * $Header: /cvsroot/pgsql/src/backend/catalog/pg_proc.c,v 1.27 1999/04/18 02:57:22 tgl Exp $ |
11 | 11 | *
|
12 | 12 | *-------------------------------------------------------------------------
|
13 | 13 | */
|
|
26 | 26 | #include"parser/parse_node.h"
|
27 | 27 | #include"tcop/tcopprot.h"
|
28 | 28 | #include"utils/builtins.h"
|
| 29 | +#include"utils/fmgrtab.h" |
29 | 30 | #include"utils/lsyscache.h"
|
30 | 31 | #include"utils/sets.h"
|
31 | 32 | #include"utils/syscache.h"
|
|
37 | 38 | #endif
|
38 | 39 |
|
39 | 40 | /* ----------------------------------------------------------------
|
40 |
| - *ProcedureDefine |
| 41 | + *ProcedureCreate |
41 | 42 | * ----------------------------------------------------------------
|
42 | 43 | */
|
43 | 44 | Oid
|
@@ -94,7 +95,7 @@ ProcedureCreate(char *procedureName,
|
94 | 95 | if (strcmp(strVal(t),"opaque")==0)
|
95 | 96 | {
|
96 | 97 | if (strcmp(languageName,"sql")==0)
|
97 |
| -elog(ERROR,"ProcedureDefine: sql functions cannot take type \"opaque\""); |
| 98 | +elog(ERROR,"ProcedureCreate: sql functions cannot take type \"opaque\""); |
98 | 99 | toid=0;
|
99 | 100 | }
|
100 | 101 | else
|
@@ -220,6 +221,32 @@ ProcedureCreate(char *procedureName,
|
220 | 221 | pg_checkretval(typeObjectId,querytree_list);
|
221 | 222 | }
|
222 | 223 |
|
| 224 | +/* |
| 225 | + * If this is an internal procedure, check that the given internal |
| 226 | + * function name (the 'prosrc' value) is a known builtin function. |
| 227 | + * |
| 228 | + * NOTE: in Postgres versions before 6.5, the SQL name of the created |
| 229 | + * function could not be different from the internal name, and 'prosrc' |
| 230 | + * wasn't used. So there is code out there that does CREATE FUNCTION |
| 231 | + * xyz AS '' LANGUAGE 'internal'. To preserve some modicum of |
| 232 | + * backwards compatibility, accept an empty 'prosrc' value as meaning |
| 233 | + * the supplied SQL function name. |
| 234 | + */ |
| 235 | + |
| 236 | +if (strcmp(languageName,"internal")==0) |
| 237 | +{ |
| 238 | +if (strlen(prosrc)==0) |
| 239 | +prosrc=procedureName; |
| 240 | +if (fmgr_lookupByName(prosrc)== (func_ptr)NULL) |
| 241 | +elog(ERROR, |
| 242 | +"ProcedureCreate: there is no builtin function named \"%s\"", |
| 243 | +prosrc); |
| 244 | +} |
| 245 | + |
| 246 | +/* |
| 247 | + * All seems OK; prepare the tuple to be inserted into pg_proc. |
| 248 | + */ |
| 249 | + |
223 | 250 | for (i=0;i<Natts_pg_proc;++i)
|
224 | 251 | {
|
225 | 252 | nulls[i]=' ';
|
|