1ALTER FUNCTION(7)        PostgreSQL 13.3 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           [ NO ] 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       DEPENDS ON EXTENSION extension_name
78       NO DEPENDS ON EXTENSION extension_name
79           This form marks the function as dependent on the extension, or no
80           longer dependent on that extension if NO is specified. A function
81           that's marked as dependent on an extension is automatically dropped
82           when the extension is dropped.
83
84       CALLED ON NULL INPUT
85       RETURNS NULL ON NULL INPUT
86       STRICT
87           CALLED ON NULL INPUT changes the function so that it will be
88           invoked when some or all of its arguments are null.  RETURNS NULL
89           ON NULL INPUT or STRICT changes the function so that it is not
90           invoked if any of its arguments are null; instead, a null result is
91           assumed automatically. See CREATE FUNCTION (CREATE_FUNCTION(7)) for
92           more information.
93
94       IMMUTABLE
95       STABLE
96       VOLATILE
97           Change the volatility of the function to the specified setting. See
98           CREATE FUNCTION (CREATE_FUNCTION(7)) for details.
99
100       [ EXTERNAL ] SECURITY INVOKER
101       [ EXTERNAL ] SECURITY DEFINER
102           Change whether the function is a security definer or not. The key
103           word EXTERNAL is ignored for SQL conformance. See CREATE FUNCTION
104           (CREATE_FUNCTION(7)) for more information about this capability.
105
106       PARALLEL
107           Change whether the function is deemed safe for parallelism. See
108           CREATE FUNCTION (CREATE_FUNCTION(7)) for details.
109
110       LEAKPROOF
111           Change whether the function is considered leakproof or not. See
112           CREATE FUNCTION (CREATE_FUNCTION(7)) for more information about
113           this capability.
114
115       COST execution_cost
116           Change the estimated execution cost of the function. See CREATE
117           FUNCTION (CREATE_FUNCTION(7)) for more information.
118
119       ROWS result_rows
120           Change the estimated number of rows returned by a set-returning
121           function. See CREATE FUNCTION (CREATE_FUNCTION(7)) for more
122           information.
123
124       SUPPORT support_function
125           Set or change the planner support function to use for this
126           function. See Section 37.11 for details. You must be superuser to
127           use this option.
128
129           This option cannot be used to remove the support function
130           altogether, since it must name a new support function. Use CREATE
131           OR REPLACE FUNCTION if you need to do that.
132
133       configuration_parameter
134       value
135           Add or change the assignment to be made to a configuration
136           parameter when the function is called. If value is DEFAULT or,
137           equivalently, RESET is used, the function-local setting is removed,
138           so that the function executes with the value present in its
139           environment. Use RESET ALL to clear all function-local settings.
140           SET FROM CURRENT saves the value of the parameter that is current
141           when ALTER FUNCTION is executed as the value to be applied when the
142           function is entered.
143
144           See SET(7) and Chapter 19 for more information about allowed
145           parameter names and values.
146
147       RESTRICT
148           Ignored for conformance with the SQL standard.
149

EXAMPLES

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

COMPATIBILITY

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

SEE ALSO

189       CREATE FUNCTION (CREATE_FUNCTION(7)), DROP FUNCTION (DROP_FUNCTION(7)),
190       ALTER PROCEDURE (ALTER_PROCEDURE(7)), ALTER ROUTINE (ALTER_ROUTINE(7))
191
192
193
194PostgreSQL 13.3                      2021                    ALTER FUNCTION(7)
Impressum