1ALTER FUNCTION(7)        PostgreSQL 12.6 Documentation       ALTER FUNCTION(7)
2
3
4

NAME

6       ALTER_FUNCTION - change the definition of a function
7

SYNOPSIS

9       ALTER FUNCTION name [ ( [ [ argmode ] [ argname ] argtype [, ...] ] ) ]
10           action [ ... ] [ RESTRICT ]
11       ALTER FUNCTION name [ ( [ [ argmode ] [ argname ] argtype [, ...] ] ) ]
12           RENAME TO new_name
13       ALTER FUNCTION name [ ( [ [ argmode ] [ argname ] argtype [, ...] ] ) ]
14           OWNER TO { new_owner | CURRENT_USER | SESSION_USER }
15       ALTER FUNCTION name [ ( [ [ argmode ] [ argname ] argtype [, ...] ] ) ]
16           SET SCHEMA new_schema
17       ALTER FUNCTION name [ ( [ [ argmode ] [ argname ] argtype [, ...] ] ) ]
18           DEPENDS ON EXTENSION extension_name
19
20       where action is one of:
21
22           CALLED ON NULL INPUT | RETURNS NULL ON NULL INPUT | STRICT
23           IMMUTABLE | STABLE | VOLATILE | [ NOT ] LEAKPROOF
24           [ EXTERNAL ] SECURITY INVOKER | [ EXTERNAL ] SECURITY DEFINER
25           PARALLEL { UNSAFE | RESTRICTED | SAFE }
26           COST execution_cost
27           ROWS result_rows
28           SUPPORT support_function
29           SET configuration_parameter { TO | = } { value | DEFAULT }
30           SET configuration_parameter FROM CURRENT
31           RESET configuration_parameter
32           RESET ALL
33

DESCRIPTION

35       ALTER FUNCTION changes the definition of a function.
36
37       You must own the function to use ALTER FUNCTION. To change a function's
38       schema, you must also have CREATE privilege on the new schema. To alter
39       the owner, you must also be a direct or indirect member of the new
40       owning role, and that role must have CREATE privilege on the function's
41       schema. (These restrictions enforce that altering the owner doesn't do
42       anything you couldn't do by dropping and recreating the function.
43       However, a superuser can alter ownership of any function anyway.)
44

PARAMETERS

46       name
47           The name (optionally schema-qualified) of an existing function. If
48           no argument list is specified, the name must be unique in its
49           schema.
50
51       argmode
52           The mode of an argument: IN, OUT, INOUT, or VARIADIC. If omitted,
53           the default is IN. Note that ALTER FUNCTION does not actually pay
54           any attention to OUT arguments, since only the input arguments are
55           needed to determine the function's identity. So it is sufficient to
56           list the IN, INOUT, and VARIADIC arguments.
57
58       argname
59           The name of an argument. Note that ALTER FUNCTION does not actually
60           pay any attention to argument names, since only the argument data
61           types are needed to determine the function's identity.
62
63       argtype
64           The data type(s) of the function's arguments (optionally
65           schema-qualified), if any.
66
67       new_name
68           The new name of the function.
69
70       new_owner
71           The new owner of the function. Note that if the function is marked
72           SECURITY DEFINER, it will subsequently execute as the new owner.
73
74       new_schema
75           The new schema for the function.
76
77       extension_name
78           The name of the extension that the function is to depend on.
79
80       CALLED ON NULL INPUT
81       RETURNS NULL ON NULL INPUT
82       STRICT
83           CALLED ON NULL INPUT changes the function so that it will be
84           invoked when some or all of its arguments are null.  RETURNS NULL
85           ON NULL INPUT or STRICT changes the function so that it is not
86           invoked if any of its arguments are null; instead, a null result is
87           assumed automatically. See CREATE FUNCTION (CREATE_FUNCTION(7)) for
88           more information.
89
90       IMMUTABLE
91       STABLE
92       VOLATILE
93           Change the volatility of the function to the specified setting. See
94           CREATE FUNCTION (CREATE_FUNCTION(7)) for details.
95
96       [ EXTERNAL ] SECURITY INVOKER
97       [ EXTERNAL ] SECURITY DEFINER
98           Change whether the function is a security definer or not. The key
99           word EXTERNAL is ignored for SQL conformance. See CREATE FUNCTION
100           (CREATE_FUNCTION(7)) for more information about this capability.
101
102       PARALLEL
103           Change whether the function is deemed safe for parallelism. See
104           CREATE FUNCTION (CREATE_FUNCTION(7)) for details.
105
106       LEAKPROOF
107           Change whether the function is considered leakproof or not. See
108           CREATE FUNCTION (CREATE_FUNCTION(7)) for more information about
109           this capability.
110
111       COST execution_cost
112           Change the estimated execution cost of the function. See CREATE
113           FUNCTION (CREATE_FUNCTION(7)) for more information.
114
115       ROWS result_rows
116           Change the estimated number of rows returned by a set-returning
117           function. See CREATE FUNCTION (CREATE_FUNCTION(7)) for more
118           information.
119
120       SUPPORT support_function
121           Set or change the planner support function to use for this
122           function. See Section 37.11 for details. You must be superuser to
123           use this option.
124
125           This option cannot be used to remove the support function
126           altogether, since it must name a new support function. Use CREATE
127           OR REPLACE FUNCTION if you need to do that.
128
129       configuration_parameter
130       value
131           Add or change the assignment to be made to a configuration
132           parameter when the function is called. If value is DEFAULT or,
133           equivalently, RESET is used, the function-local setting is removed,
134           so that the function executes with the value present in its
135           environment. Use RESET ALL to clear all function-local settings.
136           SET FROM CURRENT saves the value of the parameter that is current
137           when ALTER FUNCTION is executed as the value to be applied when the
138           function is entered.
139
140           See SET(7) and Chapter 19 for more information about allowed
141           parameter names and values.
142
143       RESTRICT
144           Ignored for conformance with the SQL standard.
145

EXAMPLES

147       To rename the function sqrt for type integer to square_root:
148
149           ALTER FUNCTION sqrt(integer) RENAME TO square_root;
150
151       To change the owner of the function sqrt for type integer to joe:
152
153           ALTER FUNCTION sqrt(integer) OWNER TO joe;
154
155       To change the schema of the function sqrt for type integer to maths:
156
157           ALTER FUNCTION sqrt(integer) SET SCHEMA maths;
158
159       To mark the function sqrt for type integer as being dependent on the
160       extension mathlib:
161
162           ALTER FUNCTION sqrt(integer) DEPENDS ON EXTENSION mathlib;
163
164       To adjust the search path that is automatically set for a function:
165
166           ALTER FUNCTION check_password(text) SET search_path = admin, pg_temp;
167
168       To disable automatic setting of search_path for a function:
169
170           ALTER FUNCTION check_password(text) RESET search_path;
171
172       The function will now execute with whatever search path is used by its
173       caller.
174

COMPATIBILITY

176       This statement is partially compatible with the ALTER FUNCTION
177       statement in the SQL standard. The standard allows more properties of a
178       function to be modified, but does not provide the ability to rename a
179       function, make a function a security definer, attach configuration
180       parameter values to a function, or change the owner, schema, or
181       volatility of a function. The standard also requires the RESTRICT key
182       word, which is optional in PostgreSQL.
183

SEE ALSO

185       CREATE FUNCTION (CREATE_FUNCTION(7)), DROP FUNCTION (DROP_FUNCTION(7)),
186       ALTER PROCEDURE (ALTER_PROCEDURE(7)), ALTER ROUTINE (ALTER_ROUTINE(7))
187
188
189
190PostgreSQL 12.6                      2021                    ALTER FUNCTION(7)
Impressum