aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>1999-04-18 02:57:22 +0000
committerTom Lane <tgl@sss.pgh.pa.us>1999-04-18 02:57:22 +0000
commit4b82c6d940643b752ce70356c2523f014cf1bff9 (patch)
tree969ec72a1b2dd80e3237258f8424bc875ce82f5a
parent00a4196139ab15110c5e46e1002fe7ad523250d8 (diff)
downloadpostgresql-4b82c6d940643b752ce70356c2523f014cf1bff9.tar.gz
postgresql-4b82c6d940643b752ce70356c2523f014cf1bff9.zip
Allow CREATE FUNCTION xyz AS '' LANGUAGE 'internal' to
work the way it used to (ie, assume xyz is the name of the builtin function to call). Complain if an unknown builtin function name is referenced.
-rw-r--r--src/backend/catalog/pg_proc.c33
1 files changed, 30 insertions, 3 deletions
diff --git a/src/backend/catalog/pg_proc.c b/src/backend/catalog/pg_proc.c
index 71cb21822e9..90c41f57ee8 100644
--- a/src/backend/catalog/pg_proc.c
+++ b/src/backend/catalog/pg_proc.c
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/catalog/pg_proc.c,v 1.26 1999/02/21 03:48:32 scrappy Exp $
+ * $Header: /cvsroot/pgsql/src/backend/catalog/pg_proc.c,v 1.27 1999/04/18 02:57:22 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -26,6 +26,7 @@
#include "parser/parse_node.h"
#include "tcop/tcopprot.h"
#include "utils/builtins.h"
+#include "utils/fmgrtab.h"
#include "utils/lsyscache.h"
#include "utils/sets.h"
#include "utils/syscache.h"
@@ -37,7 +38,7 @@
#endif
/* ----------------------------------------------------------------
- * ProcedureDefine
+ * ProcedureCreate
* ----------------------------------------------------------------
*/
Oid
@@ -94,7 +95,7 @@ ProcedureCreate(char *procedureName,
if (strcmp(strVal(t), "opaque") == 0)
{
if (strcmp(languageName, "sql") == 0)
- elog(ERROR, "ProcedureDefine: sql functions cannot take type \"opaque\"");
+ elog(ERROR, "ProcedureCreate: sql functions cannot take type \"opaque\"");
toid = 0;
}
else
@@ -220,6 +221,32 @@ ProcedureCreate(char *procedureName,
pg_checkretval(typeObjectId, querytree_list);
}
+ /*
+ * If this is an internal procedure, check that the given internal
+ * function name (the 'prosrc' value) is a known builtin function.
+ *
+ * NOTE: in Postgres versions before 6.5, the SQL name of the created
+ * function could not be different from the internal name, and 'prosrc'
+ * wasn't used. So there is code out there that does CREATE FUNCTION
+ * xyz AS '' LANGUAGE 'internal'. To preserve some modicum of
+ * backwards compatibility, accept an empty 'prosrc' value as meaning
+ * the supplied SQL function name.
+ */
+
+ if (strcmp(languageName, "internal") == 0)
+ {
+ if (strlen(prosrc) == 0)
+ prosrc = procedureName;
+ if (fmgr_lookupByName(prosrc) == (func_ptr) NULL)
+ elog(ERROR,
+ "ProcedureCreate: there is no builtin function named \"%s\"",
+ prosrc);
+ }
+
+ /*
+ * All seems OK; prepare the tuple to be inserted into pg_proc.
+ */
+
for (i = 0; i < Natts_pg_proc; ++i)
{
nulls[i] = ' ';