2
doc/src/sgml/ref/alter_function.sgml
3
PostgreSQL documentation
6
<refentry id="SQL-ALTERFUNCTION">
8
<refentrytitle>ALTER FUNCTION</refentrytitle>
9
<manvolnum>7</manvolnum>
10
<refmiscinfo>SQL - Language Statements</refmiscinfo>
14
<refname>ALTER FUNCTION</refname>
15
<refpurpose>change the definition of a function</refpurpose>
18
<indexterm zone="sql-alterfunction">
19
<primary>ALTER FUNCTION</primary>
24
ALTER FUNCTION <replaceable>name</replaceable> ( [ [ <replaceable class="parameter">argmode</replaceable> ] [ <replaceable class="parameter">argname</replaceable> ] <replaceable class="parameter">argtype</replaceable> [, ...] ] )
25
<replaceable class="PARAMETER">action</replaceable> [ ... ] [ RESTRICT ]
26
ALTER FUNCTION <replaceable>name</replaceable> ( [ [ <replaceable class="parameter">argmode</replaceable> ] [ <replaceable class="parameter">argname</replaceable> ] <replaceable class="parameter">argtype</replaceable> [, ...] ] )
27
RENAME TO <replaceable>new_name</replaceable>
28
ALTER FUNCTION <replaceable>name</replaceable> ( [ [ <replaceable class="parameter">argmode</replaceable> ] [ <replaceable class="parameter">argname</replaceable> ] <replaceable class="parameter">argtype</replaceable> [, ...] ] )
29
OWNER TO <replaceable>new_owner</replaceable>
30
ALTER FUNCTION <replaceable>name</replaceable> ( [ [ <replaceable class="parameter">argmode</replaceable> ] [ <replaceable class="parameter">argname</replaceable> ] <replaceable class="parameter">argtype</replaceable> [, ...] ] )
31
SET SCHEMA <replaceable>new_schema</replaceable>
33
<phrase>where <replaceable class="PARAMETER">action</replaceable> is one of:</phrase>
35
CALLED ON NULL INPUT | RETURNS NULL ON NULL INPUT | STRICT
36
IMMUTABLE | STABLE | VOLATILE
37
[ EXTERNAL ] SECURITY INVOKER | [ EXTERNAL ] SECURITY DEFINER
38
COST <replaceable class="parameter">execution_cost</replaceable>
39
ROWS <replaceable class="parameter">result_rows</replaceable>
40
SET <replaceable class="parameter">configuration_parameter</replaceable> { TO | = } { <replaceable class="parameter">value</replaceable> | DEFAULT }
41
SET <replaceable class="parameter">configuration_parameter</replaceable> FROM CURRENT
42
RESET <replaceable class="parameter">configuration_parameter</replaceable>
48
<title>Description</title>
51
<command>ALTER FUNCTION</command> changes the definition of a
56
You must own the function to use <command>ALTER FUNCTION</>.
57
To change a function's schema, you must also have <literal>CREATE</>
58
privilege on the new schema.
59
To alter the owner, you must also be a direct or indirect member of the new
60
owning role, and that role must have <literal>CREATE</literal> privilege on
61
the function's schema. (These restrictions enforce that altering the owner
62
doesn't do anything you couldn't do by dropping and recreating the function.
63
However, a superuser can alter ownership of any function anyway.)
68
<title>Parameters</title>
72
<term><replaceable class="parameter">name</replaceable></term>
75
The name (optionally schema-qualified) of an existing function.
81
<term><replaceable class="parameter">argmode</replaceable></term>
85
The mode of an argument: <literal>IN</>, <literal>OUT</>,
86
<literal>INOUT</>, or <literal>VARIADIC</>.
87
If omitted, the default is <literal>IN</>.
88
Note that <command>ALTER FUNCTION</command> does not actually pay
89
any attention to <literal>OUT</> arguments, since only the input
90
arguments are needed to determine the function's identity.
91
So it is sufficient to list the <literal>IN</>, <literal>INOUT</>,
92
and <literal>VARIADIC</> arguments.
98
<term><replaceable class="parameter">argname</replaceable></term>
102
The name of an argument.
103
Note that <command>ALTER FUNCTION</command> does not actually pay
104
any attention to argument names, since only the argument data
105
types are needed to determine the function's identity.
111
<term><replaceable class="parameter">argtype</replaceable></term>
115
The data type(s) of the function's arguments (optionally
116
schema-qualified), if any.
122
<term><replaceable class="parameter">new_name</replaceable></term>
125
The new name of the function.
131
<term><replaceable class="parameter">new_owner</replaceable></term>
134
The new owner of the function. Note that if the function is
135
marked <literal>SECURITY DEFINER</literal>, it will subsequently
136
execute as the new owner.
142
<term><replaceable class="parameter">new_schema</replaceable></term>
145
The new schema for the function.
151
<term><literal>CALLED ON NULL INPUT</literal></term>
152
<term><literal>RETURNS NULL ON NULL INPUT</literal></term>
153
<term><literal>STRICT</literal></term>
157
<literal>CALLED ON NULL INPUT</literal> changes the function so
158
that it will be invoked when some or all of its arguments are
159
null. <literal>RETURNS NULL ON NULL INPUT</literal> or
160
<literal>STRICT</literal> changes the function so that it is not
161
invoked if any of its arguments are null; instead, a null result
162
is assumed automatically. See <xref linkend="sql-createfunction">
163
for more information.
169
<term><literal>IMMUTABLE</literal></term>
170
<term><literal>STABLE</literal></term>
171
<term><literal>VOLATILE</literal></term>
175
Change the volatility of the function to the specified setting.
176
See <xref linkend="sql-createfunction"> for details.
182
<term><literal><optional> EXTERNAL </optional> SECURITY INVOKER</literal></term>
183
<term><literal><optional> EXTERNAL </optional> SECURITY DEFINER</literal></term>
187
Change whether the function is a security definer or not. The
188
key word <literal>EXTERNAL</literal> is ignored for SQL
189
conformance. See <xref linkend="sql-createfunction"> for more information about
196
<term><literal>COST</literal> <replaceable class="parameter">execution_cost</replaceable></term>
200
Change the estimated execution cost of the function.
201
See <xref linkend="sql-createfunction"> for more information.
207
<term><literal>ROWS</literal> <replaceable class="parameter">result_rows</replaceable></term>
211
Change the estimated number of rows returned by a set-returning
212
function. See <xref linkend="sql-createfunction"> for more information.
218
<term><replaceable>configuration_parameter</replaceable></term>
219
<term><replaceable>value</replaceable></term>
222
Add or change the assignment to be made to a configuration parameter
223
when the function is called. If
224
<replaceable>value</replaceable> is <literal>DEFAULT</literal>
225
or, equivalently, <literal>RESET</literal> is used, the function-local
226
setting is removed, so that the function executes with the value
227
present in its environment. Use <literal>RESET
228
ALL</literal> to clear all function-local settings.
229
<literal>SET FROM CURRENT</> saves the session's current value of
230
the parameter as the value to be applied when the function is entered.
234
See <xref linkend="sql-set"> and
235
<xref linkend="runtime-config">
236
for more information about allowed parameter names and values.
242
<term><literal>RESTRICT</literal></term>
246
Ignored for conformance with the SQL standard.
254
<title>Examples</title>
257
To rename the function <literal>sqrt</literal> for type
258
<type>integer</type> to <literal>square_root</literal>:
260
ALTER FUNCTION sqrt(integer) RENAME TO square_root;
265
To change the owner of the function <literal>sqrt</literal> for type
266
<type>integer</type> to <literal>joe</literal>:
268
ALTER FUNCTION sqrt(integer) OWNER TO joe;
273
To change the schema of the function <literal>sqrt</literal> for type
274
<type>integer</type> to <literal>maths</literal>:
276
ALTER FUNCTION sqrt(integer) SET SCHEMA maths;
281
To adjust the search path that is automatically set for a function:
283
ALTER FUNCTION check_password(text) SET search_path = admin, pg_temp;
288
To disable automatic setting of <varname>search_path</> for a function:
290
ALTER FUNCTION check_password(text) RESET search_path;
292
The function will now execute with whatever search path is used by its
298
<title>Compatibility</title>
301
This statement is partially compatible with the <command>ALTER
302
FUNCTION</> statement in the SQL standard. The standard allows more
303
properties of a function to be modified, but does not provide the
304
ability to rename a function, make a function a security definer,
305
attach configuration parameter values to a function,
306
or change the owner, schema, or volatility of a function. The standard also
307
requires the <literal>RESTRICT</> key word, which is optional in
308
<productname>PostgreSQL</>.
313
<title>See Also</title>
315
<simplelist type="inline">
316
<member><xref linkend="sql-createfunction"></member>
317
<member><xref linkend="sql-dropfunction"></member>