Commit aefeb687 authored by Peter Eisentraut's avatar Peter Eisentraut

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: default avatarMichael Paquier <michael.paquier@gmail.com>
parent 3f6ea5fc
...@@ -39,7 +39,7 @@ ALTER EXTENSION <replaceable class="PARAMETER">name</replaceable> DROP <replacea ...@@ -39,7 +39,7 @@ ALTER EXTENSION <replaceable class="PARAMETER">name</replaceable> DROP <replacea
EVENT TRIGGER <replaceable class="PARAMETER">object_name</replaceable> | EVENT TRIGGER <replaceable class="PARAMETER">object_name</replaceable> |
FOREIGN DATA WRAPPER <replaceable class="PARAMETER">object_name</replaceable> | FOREIGN DATA WRAPPER <replaceable class="PARAMETER">object_name</replaceable> |
FOREIGN TABLE <replaceable class="PARAMETER">object_name</replaceable> | FOREIGN TABLE <replaceable class="PARAMETER">object_name</replaceable> |
FUNCTION <replaceable class="PARAMETER">function_name</replaceable> ( [ [ <replaceable class="parameter">argmode</replaceable> ] [ <replaceable class="parameter">argname</replaceable> ] <replaceable class="parameter">argtype</replaceable> [, ...] ] ) | FUNCTION <replaceable class="PARAMETER">function_name</replaceable> [ ( [ [ <replaceable class="parameter">argmode</replaceable> ] [ <replaceable class="parameter">argname</replaceable> ] <replaceable class="parameter">argtype</replaceable> [, ...] ] ) ] |
MATERIALIZED VIEW <replaceable class="PARAMETER">object_name</replaceable> | MATERIALIZED VIEW <replaceable class="PARAMETER">object_name</replaceable> |
OPERATOR <replaceable class="PARAMETER">operator_name</replaceable> (<replaceable class="PARAMETER">left_type</replaceable>, <replaceable class="PARAMETER">right_type</replaceable>) | OPERATOR <replaceable class="PARAMETER">operator_name</replaceable> (<replaceable class="PARAMETER">left_type</replaceable>, <replaceable class="PARAMETER">right_type</replaceable>) |
OPERATOR CLASS <replaceable class="PARAMETER">object_name</replaceable> USING <replaceable class="parameter">index_method</replaceable> | OPERATOR CLASS <replaceable class="PARAMETER">object_name</replaceable> USING <replaceable class="parameter">index_method</replaceable> |
......
...@@ -21,15 +21,15 @@ PostgreSQL documentation ...@@ -21,15 +21,15 @@ PostgreSQL documentation
<refsynopsisdiv> <refsynopsisdiv>
<synopsis> <synopsis>
ALTER FUNCTION <replaceable>name</replaceable> ( [ [ <replaceable class="parameter">argmode</replaceable> ] [ <replaceable class="parameter">argname</replaceable> ] <replaceable class="parameter">argtype</replaceable> [, ...] ] ) ALTER FUNCTION <replaceable>name</replaceable> [ ( [ [ <replaceable class="parameter">argmode</replaceable> ] [ <replaceable class="parameter">argname</replaceable> ] <replaceable class="parameter">argtype</replaceable> [, ...] ] ) ]
<replaceable class="PARAMETER">action</replaceable> [ ... ] [ RESTRICT ] <replaceable class="PARAMETER">action</replaceable> [ ... ] [ RESTRICT ]
ALTER FUNCTION <replaceable>name</replaceable> ( [ [ <replaceable class="parameter">argmode</replaceable> ] [ <replaceable class="parameter">argname</replaceable> ] <replaceable class="parameter">argtype</replaceable> [, ...] ] ) ALTER FUNCTION <replaceable>name</replaceable> [ ( [ [ <replaceable class="parameter">argmode</replaceable> ] [ <replaceable class="parameter">argname</replaceable> ] <replaceable class="parameter">argtype</replaceable> [, ...] ] ) ]
RENAME TO <replaceable>new_name</replaceable> RENAME TO <replaceable>new_name</replaceable>
ALTER FUNCTION <replaceable>name</replaceable> ( [ [ <replaceable class="parameter">argmode</replaceable> ] [ <replaceable class="parameter">argname</replaceable> ] <replaceable class="parameter">argtype</replaceable> [, ...] ] ) ALTER FUNCTION <replaceable>name</replaceable> [ ( [ [ <replaceable class="parameter">argmode</replaceable> ] [ <replaceable class="parameter">argname</replaceable> ] <replaceable class="parameter">argtype</replaceable> [, ...] ] ) ]
OWNER TO { <replaceable>new_owner</replaceable> | CURRENT_USER | SESSION_USER } OWNER TO { <replaceable>new_owner</replaceable> | CURRENT_USER | SESSION_USER }
ALTER FUNCTION <replaceable>name</replaceable> ( [ [ <replaceable class="parameter">argmode</replaceable> ] [ <replaceable class="parameter">argname</replaceable> ] <replaceable class="parameter">argtype</replaceable> [, ...] ] ) ALTER FUNCTION <replaceable>name</replaceable> [ ( [ [ <replaceable class="parameter">argmode</replaceable> ] [ <replaceable class="parameter">argname</replaceable> ] <replaceable class="parameter">argtype</replaceable> [, ...] ] ) ]
SET SCHEMA <replaceable>new_schema</replaceable> SET SCHEMA <replaceable>new_schema</replaceable>
ALTER FUNCTION <replaceable>name</replaceable> ( [ [ <replaceable class="parameter">argmode</replaceable> ] [ <replaceable class="parameter">argname</replaceable> ] <replaceable class="parameter">argtype</replaceable> [, ...] ] ) ALTER FUNCTION <replaceable>name</replaceable> [ ( [ [ <replaceable class="parameter">argmode</replaceable> ] [ <replaceable class="parameter">argname</replaceable> ] <replaceable class="parameter">argtype</replaceable> [, ...] ] ) ]
DEPENDS ON EXTENSION <replaceable>extension_name</replaceable> DEPENDS ON EXTENSION <replaceable>extension_name</replaceable>
<phrase>where <replaceable class="PARAMETER">action</replaceable> is one of:</phrase> <phrase>where <replaceable class="PARAMETER">action</replaceable> is one of:</phrase>
...@@ -75,7 +75,8 @@ ALTER FUNCTION <replaceable>name</replaceable> ( [ [ <replaceable class="paramet ...@@ -75,7 +75,8 @@ ALTER FUNCTION <replaceable>name</replaceable> ( [ [ <replaceable class="paramet
<term><replaceable class="parameter">name</replaceable></term> <term><replaceable class="parameter">name</replaceable></term>
<listitem> <listitem>
<para> <para>
The name (optionally schema-qualified) of an existing function. The name (optionally schema-qualified) of an existing function. If no
argument list is specified, the name must be unique in its schema.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
......
...@@ -25,7 +25,7 @@ ALTER OPERATOR FAMILY <replaceable>name</replaceable> USING <replaceable class=" ...@@ -25,7 +25,7 @@ ALTER OPERATOR FAMILY <replaceable>name</replaceable> USING <replaceable class="
{ OPERATOR <replaceable class="parameter">strategy_number</replaceable> <replaceable class="parameter">operator_name</replaceable> ( <replaceable class="parameter">op_type</replaceable>, <replaceable class="parameter">op_type</replaceable> ) { OPERATOR <replaceable class="parameter">strategy_number</replaceable> <replaceable class="parameter">operator_name</replaceable> ( <replaceable class="parameter">op_type</replaceable>, <replaceable class="parameter">op_type</replaceable> )
[ FOR SEARCH | FOR ORDER BY <replaceable class="parameter">sort_family_name</replaceable> ] [ FOR SEARCH | FOR ORDER BY <replaceable class="parameter">sort_family_name</replaceable> ]
| FUNCTION <replaceable class="parameter">support_number</replaceable> [ ( <replaceable class="parameter">op_type</replaceable> [ , <replaceable class="parameter">op_type</replaceable> ] ) ] | FUNCTION <replaceable class="parameter">support_number</replaceable> [ ( <replaceable class="parameter">op_type</replaceable> [ , <replaceable class="parameter">op_type</replaceable> ] ) ]
<replaceable class="parameter">function_name</replaceable> ( <replaceable class="parameter">argument_type</replaceable> [, ...] ) <replaceable class="parameter">function_name</replaceable> [ ( <replaceable class="parameter">argument_type</replaceable> [, ...] ) ]
} [, ... ] } [, ... ]
ALTER OPERATOR FAMILY <replaceable>name</replaceable> USING <replaceable class="parameter">index_method</replaceable> DROP ALTER OPERATOR FAMILY <replaceable>name</replaceable> USING <replaceable class="parameter">index_method</replaceable> DROP
...@@ -195,8 +195,9 @@ ALTER OPERATOR FAMILY <replaceable>name</replaceable> USING <replaceable class=" ...@@ -195,8 +195,9 @@ ALTER OPERATOR FAMILY <replaceable>name</replaceable> USING <replaceable class="
<term><replaceable class="parameter">function_name</replaceable></term> <term><replaceable class="parameter">function_name</replaceable></term>
<listitem> <listitem>
<para> <para>
The name (optionally schema-qualified) of a function that is an The name (optionally schema-qualified) of a function that is an index
index method support procedure for the operator family. method support procedure for the operator family. If no argument list
is specified, the name must be unique in its schema.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
......
...@@ -37,7 +37,7 @@ COMMENT ON ...@@ -37,7 +37,7 @@ COMMENT ON
EVENT TRIGGER <replaceable class="PARAMETER">object_name</replaceable> | EVENT TRIGGER <replaceable class="PARAMETER">object_name</replaceable> |
FOREIGN DATA WRAPPER <replaceable class="PARAMETER">object_name</replaceable> | FOREIGN DATA WRAPPER <replaceable class="PARAMETER">object_name</replaceable> |
FOREIGN TABLE <replaceable class="PARAMETER">object_name</replaceable> | FOREIGN TABLE <replaceable class="PARAMETER">object_name</replaceable> |
FUNCTION <replaceable class="PARAMETER">function_name</replaceable> ( [ [ <replaceable class="parameter">argmode</replaceable> ] [ <replaceable class="parameter">argname</replaceable> ] <replaceable class="parameter">argtype</replaceable> [, ...] ] ) | FUNCTION <replaceable class="PARAMETER">function_name</replaceable> [ ( [ [ <replaceable class="parameter">argmode</replaceable> ] [ <replaceable class="parameter">argname</replaceable> ] <replaceable class="parameter">argtype</replaceable> [, ...] ] ) ] |
INDEX <replaceable class="PARAMETER">object_name</replaceable> | INDEX <replaceable class="PARAMETER">object_name</replaceable> |
LARGE OBJECT <replaceable class="PARAMETER">large_object_oid</replaceable> | LARGE OBJECT <replaceable class="PARAMETER">large_object_oid</replaceable> |
MATERIALIZED VIEW <replaceable class="PARAMETER">object_name</replaceable> | MATERIALIZED VIEW <replaceable class="PARAMETER">object_name</replaceable> |
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
<refsynopsisdiv> <refsynopsisdiv>
<synopsis> <synopsis>
CREATE CAST (<replaceable>source_type</replaceable> AS <replaceable>target_type</replaceable>) CREATE CAST (<replaceable>source_type</replaceable> AS <replaceable>target_type</replaceable>)
WITH FUNCTION <replaceable>function_name</replaceable> (<replaceable>argument_type</replaceable> [, ...]) WITH FUNCTION <replaceable>function_name</replaceable> [ (<replaceable>argument_type</replaceable> [, ...]) ]
[ AS ASSIGNMENT | AS IMPLICIT ] [ AS ASSIGNMENT | AS IMPLICIT ]
CREATE CAST (<replaceable>source_type</replaceable> AS <replaceable>target_type</replaceable>) CREATE CAST (<replaceable>source_type</replaceable> AS <replaceable>target_type</replaceable>)
...@@ -192,7 +192,7 @@ SELECT CAST ( 2 AS numeric ) + 4.0; ...@@ -192,7 +192,7 @@ SELECT CAST ( 2 AS numeric ) + 4.0;
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>
<term><replaceable>function_name</replaceable>(<replaceable>argument_type</replaceable> [, ...])</term> <term><literal><replaceable>function_name</replaceable>[(<replaceable>argument_type</replaceable> [, ...])]</literal></term>
<listitem> <listitem>
<para> <para>
...@@ -200,6 +200,8 @@ SELECT CAST ( 2 AS numeric ) + 4.0; ...@@ -200,6 +200,8 @@ SELECT CAST ( 2 AS numeric ) + 4.0;
be schema-qualified. If it is not, the function will be looked be schema-qualified. If it is not, the function will be looked
up in the schema search path. The function's result data type must up in the schema search path. The function's result data type must
match the target type of the cast. Its arguments are discussed below. match the target type of the cast. Its arguments are discussed below.
If no argument list is specified, the function name must be unique in
its schema.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
......
...@@ -19,8 +19,8 @@ ...@@ -19,8 +19,8 @@
<refsynopsisdiv> <refsynopsisdiv>
<synopsis> <synopsis>
CREATE [ OR REPLACE ] TRANSFORM FOR <replaceable>type_name</replaceable> LANGUAGE <replaceable>lang_name</replaceable> ( CREATE [ OR REPLACE ] TRANSFORM FOR <replaceable>type_name</replaceable> LANGUAGE <replaceable>lang_name</replaceable> (
FROM SQL WITH FUNCTION <replaceable>from_sql_function_name</replaceable> (<replaceable>argument_type</replaceable> [, ...]), FROM SQL WITH FUNCTION <replaceable>from_sql_function_name</replaceable> [ (<replaceable>argument_type</replaceable> [, ...]) ],
TO SQL WITH FUNCTION <replaceable>to_sql_function_name</replaceable> (<replaceable>argument_type</replaceable> [, ...]) TO SQL WITH FUNCTION <replaceable>to_sql_function_name</replaceable> [ (<replaceable>argument_type</replaceable> [, ...]) ]
); );
</synopsis> </synopsis>
</refsynopsisdiv> </refsynopsisdiv>
...@@ -104,7 +104,7 @@ CREATE [ OR REPLACE ] TRANSFORM FOR <replaceable>type_name</replaceable> LANGUAG ...@@ -104,7 +104,7 @@ CREATE [ OR REPLACE ] TRANSFORM FOR <replaceable>type_name</replaceable> LANGUAG
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>
<term><replaceable>from_sql_function_name</replaceable>(<replaceable>argument_type</replaceable> [, ...])</term> <term><literal><replaceable>from_sql_function_name</replaceable>[(<replaceable>argument_type</replaceable> [, ...])]</literal></term>
<listitem> <listitem>
<para> <para>
...@@ -116,12 +116,14 @@ CREATE [ OR REPLACE ] TRANSFORM FOR <replaceable>type_name</replaceable> LANGUAG ...@@ -116,12 +116,14 @@ CREATE [ OR REPLACE ] TRANSFORM FOR <replaceable>type_name</replaceable> LANGUAG
SQL-level function returning <type>internal</type> without at SQL-level function returning <type>internal</type> without at
least one argument of type <type>internal</type>.) The actual return least one argument of type <type>internal</type>.) The actual return
value will be something specific to the language implementation. value will be something specific to the language implementation.
If no argument list is specified, the function name must be unique in
its schema.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>
<term><replaceable>to_sql_function_name</replaceable>(<replaceable>argument_type</replaceable> [, ...])</term> <term><literal><replaceable>to_sql_function_name</replaceable>[(<replaceable>argument_type</replaceable> [, ...])]</literal></term>
<listitem> <listitem>
<para> <para>
...@@ -130,6 +132,8 @@ CREATE [ OR REPLACE ] TRANSFORM FOR <replaceable>type_name</replaceable> LANGUAG ...@@ -130,6 +132,8 @@ CREATE [ OR REPLACE ] TRANSFORM FOR <replaceable>type_name</replaceable> LANGUAG
<type>internal</type> and return the type that is the type for the <type>internal</type> and return the type that is the type for the
transform. The actual argument value will be something specific to the transform. The actual argument value will be something specific to the
language implementation. language implementation.
If no argument list is specified, the function name must be unique in
its schema.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
......
...@@ -21,7 +21,7 @@ PostgreSQL documentation ...@@ -21,7 +21,7 @@ PostgreSQL documentation
<refsynopsisdiv> <refsynopsisdiv>
<synopsis> <synopsis>
DROP FUNCTION [ IF EXISTS ] <replaceable class="parameter">name</replaceable> ( [ [ <replaceable class="parameter">argmode</replaceable> ] [ <replaceable class="parameter">argname</replaceable> ] <replaceable class="parameter">argtype</replaceable> [, ...] ] ) [, ...] DROP FUNCTION [ IF EXISTS ] <replaceable class="parameter">name</replaceable> [ ( [ [ <replaceable class="parameter">argmode</replaceable> ] [ <replaceable class="parameter">argname</replaceable> ] <replaceable class="parameter">argtype</replaceable> [, ...] ] ) ] [, ...]
[ CASCADE | RESTRICT ] [ CASCADE | RESTRICT ]
</synopsis> </synopsis>
</refsynopsisdiv> </refsynopsisdiv>
...@@ -56,7 +56,8 @@ DROP FUNCTION [ IF EXISTS ] <replaceable class="parameter">name</replaceable> ( ...@@ -56,7 +56,8 @@ DROP FUNCTION [ IF EXISTS ] <replaceable class="parameter">name</replaceable> (
<term><replaceable class="parameter">name</replaceable></term> <term><replaceable class="parameter">name</replaceable></term>
<listitem> <listitem>
<para> <para>
The name (optionally schema-qualified) of an existing function. The name (optionally schema-qualified) of an existing function. If no
argument list is specified, the name must be unique in its schema.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
...@@ -141,14 +142,40 @@ DROP FUNCTION sqrt(integer); ...@@ -141,14 +142,40 @@ DROP FUNCTION sqrt(integer);
<programlisting> <programlisting>
DROP FUNCTION sqrt(integer), sqrt(bigint); DROP FUNCTION sqrt(integer), sqrt(bigint);
</programlisting></para> </programlisting></para>
<para>
If the function name is unique in its schema, it can be referred to without
an argument list:
<programlisting>
DROP FUNCTION update_employee_salaries;
</programlisting>
Note that this is different from
<programlisting>
DROP FUNCTION update_employee_salaries();
</programlisting>
which refers to a function with zero arguments, whereas the first variant
can refer to a function with any number of arguments, including zero, as
long as the name is unique.
</para>
</refsect1> </refsect1>
<refsect1 id="SQL-DROPFUNCTION-compatibility"> <refsect1 id="SQL-DROPFUNCTION-compatibility">
<title>Compatibility</title> <title>Compatibility</title>
<para> <para>
A <command>DROP FUNCTION</command> statement is defined in the SQL This command conforms to the SQL standard, with
standard, but it is not compatible with this command. these <productname>PostgreSQL</productname> extensions:
<itemizedlist>
<listitem>
<para>The standard only allows one function to be dropped per command.</para>
</listitem>
<listitem>
<para>The <literal>IF EXISTS</literal> option</para>
</listitem>
<listitem>
<para>The ability to specify argument modes and names</para>
</listitem>
</itemizedlist>
</para> </para>
</refsect1> </refsect1>
......
...@@ -55,7 +55,7 @@ GRANT { USAGE | ALL [ PRIVILEGES ] } ...@@ -55,7 +55,7 @@ GRANT { USAGE | ALL [ PRIVILEGES ] }
TO <replaceable class="PARAMETER">role_specification</replaceable> [, ...] [ WITH GRANT OPTION ] TO <replaceable class="PARAMETER">role_specification</replaceable> [, ...] [ WITH GRANT OPTION ]
GRANT { EXECUTE | ALL [ PRIVILEGES ] } GRANT { EXECUTE | ALL [ PRIVILEGES ] }
ON { FUNCTION <replaceable>function_name</replaceable> ( [ [ <replaceable class="parameter">argmode</replaceable> ] [ <replaceable class="parameter">arg_name</replaceable> ] <replaceable class="parameter">arg_type</replaceable> [, ...] ] ) [, ...] ON { FUNCTION <replaceable>function_name</replaceable> [ ( [ [ <replaceable class="parameter">argmode</replaceable> ] [ <replaceable class="parameter">arg_name</replaceable> ] <replaceable class="parameter">arg_type</replaceable> [, ...] ] ) ] [, ...]
| ALL FUNCTIONS IN SCHEMA <replaceable class="PARAMETER">schema_name</replaceable> [, ...] } | ALL FUNCTIONS IN SCHEMA <replaceable class="PARAMETER">schema_name</replaceable> [, ...] }
TO <replaceable class="PARAMETER">role_specification</replaceable> [, ...] [ WITH GRANT OPTION ] TO <replaceable class="PARAMETER">role_specification</replaceable> [, ...] [ WITH GRANT OPTION ]
......
...@@ -70,7 +70,7 @@ REVOKE [ GRANT OPTION FOR ] ...@@ -70,7 +70,7 @@ REVOKE [ GRANT OPTION FOR ]
REVOKE [ GRANT OPTION FOR ] REVOKE [ GRANT OPTION FOR ]
{ EXECUTE | ALL [ PRIVILEGES ] } { EXECUTE | ALL [ PRIVILEGES ] }
ON { FUNCTION <replaceable>function_name</replaceable> ( [ [ <replaceable class="parameter">argmode</replaceable> ] [ <replaceable class="parameter">arg_name</replaceable> ] <replaceable class="parameter">arg_type</replaceable> [, ...] ] ) [, ...] ON { FUNCTION <replaceable>function_name</replaceable> [ ( [ [ <replaceable class="parameter">argmode</replaceable> ] [ <replaceable class="parameter">arg_name</replaceable> ] <replaceable class="parameter">arg_type</replaceable> [, ...] ] ) ] [, ...]
| ALL FUNCTIONS IN SCHEMA <replaceable>schema_name</replaceable> [, ...] } | ALL FUNCTIONS IN SCHEMA <replaceable>schema_name</replaceable> [, ...] }
FROM { [ GROUP ] <replaceable class="PARAMETER">role_name</replaceable> | PUBLIC } [, ...] FROM { [ GROUP ] <replaceable class="PARAMETER">role_name</replaceable> | PUBLIC } [, ...]
[ CASCADE | RESTRICT ] [ CASCADE | RESTRICT ]
......
...@@ -30,7 +30,7 @@ SECURITY LABEL [ FOR <replaceable class="PARAMETER">provider</replaceable> ] ON ...@@ -30,7 +30,7 @@ SECURITY LABEL [ FOR <replaceable class="PARAMETER">provider</replaceable> ] ON
DOMAIN <replaceable class="PARAMETER">object_name</replaceable> | DOMAIN <replaceable class="PARAMETER">object_name</replaceable> |
EVENT TRIGGER <replaceable class="PARAMETER">object_name</replaceable> | EVENT TRIGGER <replaceable class="PARAMETER">object_name</replaceable> |
FOREIGN TABLE <replaceable class="PARAMETER">object_name</replaceable> FOREIGN TABLE <replaceable class="PARAMETER">object_name</replaceable>
FUNCTION <replaceable class="PARAMETER">function_name</replaceable> ( [ [ <replaceable class="parameter">argmode</replaceable> ] [ <replaceable class="parameter">argname</replaceable> ] <replaceable class="parameter">argtype</replaceable> [, ...] ] ) | FUNCTION <replaceable class="PARAMETER">function_name</replaceable> [ ( [ [ <replaceable class="parameter">argmode</replaceable> ] [ <replaceable class="parameter">argname</replaceable> ] <replaceable class="parameter">argtype</replaceable> [, ...] ] ) ] |
LARGE OBJECT <replaceable class="PARAMETER">large_object_oid</replaceable> | LARGE OBJECT <replaceable class="PARAMETER">large_object_oid</replaceable> |
MATERIALIZED VIEW <replaceable class="PARAMETER">object_name</replaceable> | MATERIALIZED VIEW <replaceable class="PARAMETER">object_name</replaceable> |
[ PROCEDURAL ] LANGUAGE <replaceable class="PARAMETER">object_name</replaceable> | [ PROCEDURAL ] LANGUAGE <replaceable class="PARAMETER">object_name</replaceable> |
......
...@@ -3067,6 +3067,7 @@ _copyObjectWithArgs(const ObjectWithArgs *from) ...@@ -3067,6 +3067,7 @@ _copyObjectWithArgs(const ObjectWithArgs *from)
COPY_NODE_FIELD(objname); COPY_NODE_FIELD(objname);
COPY_NODE_FIELD(objargs); COPY_NODE_FIELD(objargs);
COPY_SCALAR_FIELD(args_unspecified);
return newnode; return newnode;
} }
......
...@@ -1119,6 +1119,7 @@ _equalObjectWithArgs(const ObjectWithArgs *a, const ObjectWithArgs *b) ...@@ -1119,6 +1119,7 @@ _equalObjectWithArgs(const ObjectWithArgs *a, const ObjectWithArgs *b)
{ {
COMPARE_NODE_FIELD(objname); COMPARE_NODE_FIELD(objname);
COMPARE_NODE_FIELD(objargs); COMPARE_NODE_FIELD(objargs);
COMPARE_SCALAR_FIELD(args_unspecified);
return true; return true;
} }
......
...@@ -7202,6 +7202,33 @@ function_with_argtypes: ...@@ -7202,6 +7202,33 @@ function_with_argtypes:
n->objargs = extractArgTypes($2); n->objargs = extractArgTypes($2);
$$ = n; $$ = n;
} }
/*
* Because of reduce/reduce conflicts, we can't use func_name
* below, but we can write it out the long way, which actually
* allows more cases.
*/
| type_func_name_keyword
{
ObjectWithArgs *n = makeNode(ObjectWithArgs);
n->objname = list_make1(makeString(pstrdup($1)));
n->args_unspecified = true;
$$ = n;
}
| ColId
{
ObjectWithArgs *n = makeNode(ObjectWithArgs);
n->objname = list_make1(makeString($1));
n->args_unspecified = true;
$$ = n;
}
| ColId indirection
{
ObjectWithArgs *n = makeNode(ObjectWithArgs);
n->objname = check_func_name(lcons(makeString($1), $2),
yyscanner);
n->args_unspecified = true;
$$ = n;
}
; ;
/* /*
......
...@@ -1895,8 +1895,10 @@ func_signature_string(List *funcname, int nargs, ...@@ -1895,8 +1895,10 @@ func_signature_string(List *funcname, int nargs,
/* /*
* LookupFuncName * 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 * If the function name is not schema-qualified, it is sought in the current
* namespace search path. * namespace search path.
...@@ -1914,6 +1916,35 @@ LookupFuncName(List *funcname, int nargs, const Oid *argtypes, bool noError) ...@@ -1914,6 +1916,35 @@ LookupFuncName(List *funcname, int nargs, const Oid *argtypes, bool noError)
clist = FuncnameGetCandidates(funcname, nargs, NIL, false, false, 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) while (clist)
{ {
if (memcmp(argtypes, clist->args, nargs * sizeof(Oid)) == 0) if (memcmp(argtypes, clist->args, nargs * sizeof(Oid)) == 0)
...@@ -1962,7 +1993,7 @@ LookupFuncWithArgs(ObjectWithArgs *func, bool noError) ...@@ -1962,7 +1993,7 @@ LookupFuncWithArgs(ObjectWithArgs *func, bool noError)
args_item = lnext(args_item); args_item = lnext(args_item);
} }
return LookupFuncName(func->objname, argcount, argoids, noError); return LookupFuncName(func->objname, func->args_unspecified ? -1 : argcount, argoids, noError);
} }
/* /*
......
...@@ -1811,6 +1811,9 @@ typedef struct ObjectWithArgs ...@@ -1811,6 +1811,9 @@ typedef struct ObjectWithArgs
NodeTag type; NodeTag type;
List *objname; /* qualified name of function/operator */ List *objname; /* qualified name of function/operator */
List *objargs; /* list of Typename nodes */ List *objargs; /* list of Typename nodes */
bool args_unspecified; /* argument list was omitted, so name must
* be unique (note that objargs == NIL means
* zero args) */
} ObjectWithArgs; } ObjectWithArgs;
/* /*
......
...@@ -218,13 +218,21 @@ SELECT routine_name, ordinal_position, parameter_name, parameter_default ...@@ -218,13 +218,21 @@ SELECT routine_name, ordinal_position, parameter_name, parameter_default
(7 rows) (7 rows)
DROP FUNCTION functest_IS_1(int, int, text), functest_IS_2(int), functest_IS_3(int); DROP FUNCTION functest_IS_1(int, int, text), functest_IS_2(int), functest_IS_3(int);
-- overload
CREATE FUNCTION functest_B_2(bigint) RETURNS bool LANGUAGE 'sql'
IMMUTABLE AS 'SELECT $1 > 0';
DROP FUNCTION functest_b_1;
DROP FUNCTION functest_b_1; -- error, not found
ERROR: could not find a function named "functest_b_1"
DROP FUNCTION functest_b_2; -- error, ambiguous
ERROR: function name "functest_b_2" is not unique
HINT: Specify the argument list to select the function unambiguously.
-- Cleanups -- Cleanups
DROP SCHEMA temp_func_test CASCADE; DROP SCHEMA temp_func_test CASCADE;
NOTICE: drop cascades to 16 other objects NOTICE: drop cascades to 16 other objects
DETAIL: drop cascades to function functest_a_1(text,date) DETAIL: drop cascades to function functest_a_1(text,date)
drop cascades to function functest_a_2(text[]) drop cascades to function functest_a_2(text[])
drop cascades to function functest_a_3() drop cascades to function functest_a_3()
drop cascades to function functest_b_1(integer)
drop cascades to function functest_b_2(integer) drop cascades to function functest_b_2(integer)
drop cascades to function functest_b_3(integer) drop cascades to function functest_b_3(integer)
drop cascades to function functest_b_4(integer) drop cascades to function functest_b_4(integer)
...@@ -237,5 +245,6 @@ drop cascades to function functext_f_1(integer) ...@@ -237,5 +245,6 @@ drop cascades to function functext_f_1(integer)
drop cascades to function functext_f_2(integer) drop cascades to function functext_f_2(integer)
drop cascades to function functext_f_3(integer) drop cascades to function functext_f_3(integer)
drop cascades to function functext_f_4(integer) drop cascades to function functext_f_4(integer)
drop cascades to function functest_b_2(bigint)
DROP USER regress_unpriv_user; DROP USER regress_unpriv_user;
RESET search_path; RESET search_path;
...@@ -158,6 +158,14 @@ SELECT routine_name, ordinal_position, parameter_name, parameter_default ...@@ -158,6 +158,14 @@ SELECT routine_name, ordinal_position, parameter_name, parameter_default
DROP FUNCTION functest_IS_1(int, int, text), functest_IS_2(int), functest_IS_3(int); DROP FUNCTION functest_IS_1(int, int, text), functest_IS_2(int), functest_IS_3(int);
-- overload
CREATE FUNCTION functest_B_2(bigint) RETURNS bool LANGUAGE 'sql'
IMMUTABLE AS 'SELECT $1 > 0';
DROP FUNCTION functest_b_1;
DROP FUNCTION functest_b_1; -- error, not found
DROP FUNCTION functest_b_2; -- error, ambiguous
-- Cleanups -- Cleanups
DROP SCHEMA temp_func_test CASCADE; DROP SCHEMA temp_func_test CASCADE;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment