aboutsummaryrefslogtreecommitdiff
path: root/src/backend/parser/parse_func.c
diff options
context:
space:
mode:
authorPeter Eisentraut <peter_e@gmx.net>2017-03-09 23:58:48 -0500
committerPeter Eisentraut <peter_e@gmx.net>2017-03-14 23:55:19 -0400
commitaefeb68741fb9456f14b4d690b0c646e532fea6b (patch)
tree518d41fa28d38baa67d6610faa49945b0b9688a0 /src/backend/parser/parse_func.c
parent3f6ea5fc8d9c6d7c85827c87a717be0016d06b89 (diff)
downloadpostgresql-aefeb68741fb9456f14b4d690b0c646e532fea6b.tar.gz
postgresql-aefeb68741fb9456f14b4d690b0c646e532fea6b.zip
Allow referring to functions without arguments when unique
In DDL commands referring to an existing function, allow omitting the argument list if the function name is unique in its schema, per SQL standard. This uses the same logic that the regproc type uses for finding functions by name only. Reviewed-by: Michael Paquier <michael.paquier@gmail.com>
Diffstat (limited to 'src/backend/parser/parse_func.c')
-rw-r--r--src/backend/parser/parse_func.c37
1 files changed, 34 insertions, 3 deletions
diff --git a/src/backend/parser/parse_func.c b/src/backend/parser/parse_func.c
index dd9749f2056..55853c20bb4 100644
--- a/src/backend/parser/parse_func.c
+++ b/src/backend/parser/parse_func.c
@@ -1895,8 +1895,10 @@ func_signature_string(List *funcname, int nargs,
/*
* LookupFuncName
- * Given a possibly-qualified function name and a set of argument types,
- * look up the function.
+ *
+ * Given a possibly-qualified function name and optionally a set of argument
+ * types, look up the function. Pass nargs == -1 to indicate that no argument
+ * types are specified.
*
* If the function name is not schema-qualified, it is sought in the current
* namespace search path.
@@ -1914,6 +1916,35 @@ LookupFuncName(List *funcname, int nargs, const Oid *argtypes, bool noError)
clist = FuncnameGetCandidates(funcname, nargs, NIL, false, false, noError);
+ /*
+ * If no arguments were specified, the name must yield a unique candidate.
+ */
+ if (nargs == -1)
+ {
+ if (clist)
+ {
+ if (clist->next)
+ {
+ if (!noError)
+ ereport(ERROR,
+ (errcode(ERRCODE_AMBIGUOUS_FUNCTION),
+ errmsg("function name \"%s\" is not unique",
+ NameListToString(funcname)),
+ errhint("Specify the argument list to select the function unambiguously.")));
+ }
+ else
+ return clist->oid;
+ }
+ else
+ {
+ if (!noError)
+ ereport(ERROR,
+ (errcode(ERRCODE_UNDEFINED_FUNCTION),
+ errmsg("could not find a function named \"%s\"",
+ NameListToString(funcname))));
+ }
+ }
+
while (clist)
{
if (memcmp(argtypes, clist->args, nargs * sizeof(Oid)) == 0)
@@ -1962,7 +1993,7 @@ LookupFuncWithArgs(ObjectWithArgs *func, bool noError)
args_item = lnext(args_item);
}
- return LookupFuncName(func->objname, argcount, argoids, noError);
+ return LookupFuncName(func->objname, func->args_unspecified ? -1 : argcount, argoids, noError);
}
/*