2 doc/src/sgml/ref/alter_function.sgml
3 PostgreSQL documentation
6 <refentry id=
"sql-alterfunction">
7 <indexterm zone=
"sql-alterfunction">
8 <primary>ALTER FUNCTION
</primary>
12 <refentrytitle>ALTER FUNCTION
</refentrytitle>
13 <manvolnum>7</manvolnum>
14 <refmiscinfo>SQL - Language Statements
</refmiscinfo>
18 <refname>ALTER FUNCTION
</refname>
19 <refpurpose>change the definition of a function
</refpurpose>
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> | CURRENT_ROLE | CURRENT_USER | SESSION_USER }
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>
32 ALTER FUNCTION
<replaceable>name
</replaceable> [ ( [ [
<replaceable class=
"parameter">argmode
</replaceable> ] [
<replaceable class=
"parameter">argname
</replaceable> ]
<replaceable class=
"parameter">argtype
</replaceable> [, ...] ] ) ]
33 [ NO ] DEPENDS ON EXTENSION
<replaceable>extension_name
</replaceable>
35 <phrase>where
<replaceable class=
"parameter">action
</replaceable> is one of:
</phrase>
37 CALLED ON NULL INPUT | RETURNS NULL ON NULL INPUT | STRICT
38 IMMUTABLE | STABLE | VOLATILE
40 [ EXTERNAL ] SECURITY INVOKER | [ EXTERNAL ] SECURITY DEFINER
41 PARALLEL { UNSAFE | RESTRICTED | SAFE }
42 COST
<replaceable class=
"parameter">execution_cost
</replaceable>
43 ROWS
<replaceable class=
"parameter">result_rows
</replaceable>
44 SUPPORT
<replaceable class=
"parameter">support_function
</replaceable>
45 SET
<replaceable class=
"parameter">configuration_parameter
</replaceable> { TO | = } {
<replaceable class=
"parameter">value
</replaceable> | DEFAULT }
46 SET
<replaceable class=
"parameter">configuration_parameter
</replaceable> FROM CURRENT
47 RESET
<replaceable class=
"parameter">configuration_parameter
</replaceable>
53 <title>Description
</title>
56 <command>ALTER FUNCTION
</command> changes the definition of a
61 You must own the function to use
<command>ALTER FUNCTION
</command>.
62 To change a function's schema, you must also have
<literal>CREATE
</literal>
63 privilege on the new schema. To alter the owner, you must be able to
64 <literal>SET ROLE
</literal> to the new owning role, and that role must
65 have
<literal>CREATE
</literal> privilege on
66 the function's schema. (These restrictions enforce that altering the owner
67 doesn't do anything you couldn't do by dropping and recreating the function.
68 However, a superuser can alter ownership of any function anyway.)
73 <title>Parameters
</title>
77 <term><replaceable class=
"parameter">name
</replaceable></term>
80 The name (optionally schema-qualified) of an existing function. If no
81 argument list is specified, the name must be unique in its schema.
87 <term><replaceable class=
"parameter">argmode
</replaceable></term>
91 The mode of an argument:
<literal>IN
</literal>,
<literal>OUT
</literal>,
92 <literal>INOUT
</literal>, or
<literal>VARIADIC
</literal>.
93 If omitted, the default is
<literal>IN
</literal>.
94 Note that
<command>ALTER FUNCTION
</command> does not actually pay
95 any attention to
<literal>OUT
</literal> arguments, since only the input
96 arguments are needed to determine the function's identity.
97 So it is sufficient to list the
<literal>IN
</literal>,
<literal>INOUT
</literal>,
98 and
<literal>VARIADIC
</literal> arguments.
104 <term><replaceable class=
"parameter">argname
</replaceable></term>
108 The name of an argument.
109 Note that
<command>ALTER FUNCTION
</command> does not actually pay
110 any attention to argument names, since only the argument data
111 types are needed to determine the function's identity.
117 <term><replaceable class=
"parameter">argtype
</replaceable></term>
121 The data type(s) of the function's arguments (optionally
122 schema-qualified), if any.
128 <term><replaceable class=
"parameter">new_name
</replaceable></term>
131 The new name of the function.
137 <term><replaceable class=
"parameter">new_owner
</replaceable></term>
140 The new owner of the function. Note that if the function is
141 marked
<literal>SECURITY DEFINER
</literal>, it will subsequently
142 execute as the new owner.
148 <term><replaceable class=
"parameter">new_schema
</replaceable></term>
151 The new schema for the function.
157 <term><literal>DEPENDS ON EXTENSION
<replaceable class=
"parameter">extension_name
</replaceable></literal></term>
158 <term><literal>NO DEPENDS ON EXTENSION
<replaceable class=
"parameter">extension_name
</replaceable></literal></term>
161 This form marks the function as dependent on the extension, or no longer
162 dependent on that extension if
<literal>NO
</literal> is specified.
163 A function that's marked as dependent on an extension is dropped when the
164 extension is dropped, even if
<literal>CASCADE
</literal> is not specified.
165 A function can depend upon multiple extensions, and will be dropped when
166 any one of those extensions is dropped.
172 <term><literal>CALLED ON NULL INPUT
</literal></term>
173 <term><literal>RETURNS NULL ON NULL INPUT
</literal></term>
174 <term><literal>STRICT
</literal></term>
177 <para><literal>CALLED ON NULL INPUT
</literal> changes the function so
178 that it will be invoked when some or all of its arguments are
179 null.
<literal>RETURNS NULL ON NULL INPUT
</literal> or
180 <literal>STRICT
</literal> changes the function so that it is not
181 invoked if any of its arguments are null; instead, a null result
182 is assumed automatically. See
<xref linkend=
"sql-createfunction"/>
183 for more information.
189 <term><literal>IMMUTABLE
</literal></term>
190 <term><literal>STABLE
</literal></term>
191 <term><literal>VOLATILE
</literal></term>
195 Change the volatility of the function to the specified setting.
196 See
<xref linkend=
"sql-createfunction"/> for details.
202 <term><literal><optional> EXTERNAL
</optional> SECURITY INVOKER
</literal></term>
203 <term><literal><optional> EXTERNAL
</optional> SECURITY DEFINER
</literal></term>
207 Change whether the function is a security definer or not. The
208 key word
<literal>EXTERNAL
</literal> is ignored for SQL
209 conformance. See
<xref linkend=
"sql-createfunction"/> for more information about
216 <term><literal>PARALLEL
</literal></term>
220 Change whether the function is deemed safe for parallelism.
221 See
<xref linkend=
"sql-createfunction"/> for details.
227 <term><literal>LEAKPROOF
</literal></term>
230 Change whether the function is considered leakproof or not.
231 See
<xref linkend=
"sql-createfunction"/> for more information about
238 <term><literal>COST
</literal> <replaceable class=
"parameter">execution_cost
</replaceable></term>
242 Change the estimated execution cost of the function.
243 See
<xref linkend=
"sql-createfunction"/> for more information.
249 <term><literal>ROWS
</literal> <replaceable class=
"parameter">result_rows
</replaceable></term>
253 Change the estimated number of rows returned by a set-returning
254 function. See
<xref linkend=
"sql-createfunction"/> for more information.
260 <term><literal>SUPPORT
</literal> <replaceable class=
"parameter">support_function
</replaceable></term>
264 Set or change the planner support function to use for this function.
265 See
<xref linkend=
"xfunc-optimization"/> for details. You must be
266 superuser to use this option.
270 This option cannot be used to remove the support function altogether,
271 since it must name a new support function. Use
<command>CREATE OR
272 REPLACE FUNCTION
</command> if you need to do that.
278 <term><replaceable>configuration_parameter
</replaceable></term>
279 <term><replaceable>value
</replaceable></term>
282 Add or change the assignment to be made to a configuration parameter
283 when the function is called. If
284 <replaceable>value
</replaceable> is
<literal>DEFAULT
</literal>
285 or, equivalently,
<literal>RESET
</literal> is used, the function-local
286 setting is removed, so that the function executes with the value
287 present in its environment. Use
<literal>RESET
288 ALL
</literal> to clear all function-local settings.
289 <literal>SET FROM CURRENT
</literal> saves the value of the parameter that
290 is current when
<command>ALTER FUNCTION
</command> is executed as the value
291 to be applied when the function is entered.
295 See
<xref linkend=
"sql-set"/> and
296 <xref linkend=
"runtime-config"/>
297 for more information about allowed parameter names and values.
303 <term><literal>RESTRICT
</literal></term>
307 Ignored for conformance with the SQL standard.
315 <title>Examples
</title>
318 To rename the function
<literal>sqrt
</literal> for type
319 <type>integer
</type> to
<literal>square_root
</literal>:
321 ALTER FUNCTION sqrt(integer) RENAME TO square_root;
326 To change the owner of the function
<literal>sqrt
</literal> for type
327 <type>integer
</type> to
<literal>joe
</literal>:
329 ALTER FUNCTION sqrt(integer) OWNER TO joe;
334 To change the schema of the function
<literal>sqrt
</literal> for type
335 <type>integer
</type> to
<literal>maths
</literal>:
337 ALTER FUNCTION sqrt(integer) SET SCHEMA maths;
342 To mark the function
<literal>sqrt
</literal> for type
343 <type>integer
</type> as being dependent on the extension
344 <literal>mathlib
</literal>:
346 ALTER FUNCTION sqrt(integer) DEPENDS ON EXTENSION mathlib;
351 To adjust the search path that is automatically set for a function:
353 ALTER FUNCTION check_password(text) SET search_path = admin, pg_temp;
358 To disable automatic setting of
<varname>search_path
</varname> for a function:
360 ALTER FUNCTION check_password(text) RESET search_path;
362 The function will now execute with whatever search path is used by its
368 <title>Compatibility
</title>
371 This statement is partially compatible with the
<command>ALTER
372 FUNCTION
</command> statement in the SQL standard. The standard allows more
373 properties of a function to be modified, but does not provide the
374 ability to rename a function, make a function a security definer,
375 attach configuration parameter values to a function,
376 or change the owner, schema, or volatility of a function. The standard also
377 requires the
<literal>RESTRICT
</literal> key word, which is optional in
378 <productname>PostgreSQL
</productname>.
383 <title>See Also
</title>
385 <simplelist type=
"inline">
386 <member><xref linkend=
"sql-createfunction"/></member>
387 <member><xref linkend=
"sql-dropfunction"/></member>
388 <member><xref linkend=
"sql-alterprocedure"/></member>
389 <member><xref linkend=
"sql-alterroutine"/></member>