]> begriffs open source - ai-pg/blob - full-docs/txt/sql-alterfunction.txt
Convert HTML docs to more streamlined TXT
[ai-pg] / full-docs / txt / sql-alterfunction.txt
1
2 ALTER FUNCTION
3
4    ALTER FUNCTION — change the definition of a function
5
6 Synopsis
7
8 ALTER FUNCTION name [ ( [ [ argmode ] [ argname ] argtype [, ...] ] ) ]
9     action [ ... ] [ RESTRICT ]
10 ALTER FUNCTION name [ ( [ [ argmode ] [ argname ] argtype [, ...] ] ) ]
11     RENAME TO new_name
12 ALTER FUNCTION name [ ( [ [ argmode ] [ argname ] argtype [, ...] ] ) ]
13     OWNER TO { new_owner | CURRENT_ROLE | CURRENT_USER | SESSION_USER }
14 ALTER FUNCTION name [ ( [ [ argmode ] [ argname ] argtype [, ...] ] ) ]
15     SET SCHEMA new_schema
16 ALTER FUNCTION name [ ( [ [ argmode ] [ argname ] argtype [, ...] ] ) ]
17     [ NO ] DEPENDS ON EXTENSION extension_name
18
19 where action is one of:
20
21     CALLED ON NULL INPUT | RETURNS NULL ON NULL INPUT | STRICT
22     IMMUTABLE | STABLE | VOLATILE
23     [ 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
34 Description
35
36    ALTER FUNCTION changes the definition of a function.
37
38    You must own the function to use ALTER FUNCTION. To change a function's
39    schema, you must also have CREATE privilege on the new schema. To alter
40    the owner, you must be able to SET ROLE to the new owning role, and
41    that role must have CREATE privilege on the function's schema. (These
42    restrictions enforce that altering the owner doesn't do anything you
43    couldn't do by dropping and recreating the function. However, a
44    superuser can alter ownership of any function anyway.)
45
46 Parameters
47
48    name
49           The name (optionally schema-qualified) of an existing function.
50           If no argument list is specified, the name must be unique in its
51           schema.
52
53    argmode
54           The mode of an argument: IN, OUT, INOUT, or VARIADIC. If
55           omitted, the default is IN. Note that ALTER FUNCTION does not
56           actually pay any attention to OUT arguments, since only the
57           input arguments are needed to determine the function's identity.
58           So it is sufficient to list the IN, INOUT, and VARIADIC
59           arguments.
60
61    argname
62           The name of an argument. Note that ALTER FUNCTION does not
63           actually pay any attention to argument names, since only the
64           argument data types are needed to determine the function's
65           identity.
66
67    argtype
68           The data type(s) of the function's arguments (optionally
69           schema-qualified), if any.
70
71    new_name
72           The new name of the function.
73
74    new_owner
75           The new owner of the function. Note that if the function is
76           marked SECURITY DEFINER, it will subsequently execute as the new
77           owner.
78
79    new_schema
80           The new schema for the function.
81
82    DEPENDS ON EXTENSION extension_name
83           NO DEPENDS ON EXTENSION extension_name
84           This form marks the function as dependent on the extension, or
85           no longer dependent on that extension if NO is specified. A
86           function that's marked as dependent on an extension is dropped
87           when the extension is dropped, even if CASCADE is not specified.
88           A function can depend upon multiple extensions, and will be
89           dropped when any one of those extensions is dropped.
90
91    CALLED ON NULL INPUT
92           RETURNS NULL ON NULL INPUT
93           STRICT
94           CALLED ON NULL INPUT changes the function so that it will be
95           invoked when some or all of its arguments are null. RETURNS NULL
96           ON NULL INPUT or STRICT changes the function so that it is not
97           invoked if any of its arguments are null; instead, a null result
98           is assumed automatically. See CREATE FUNCTION for more
99           information.
100
101    IMMUTABLE
102           STABLE
103           VOLATILE
104           Change the volatility of the function to the specified setting.
105           See CREATE FUNCTION for details.
106
107    [ EXTERNAL ] SECURITY INVOKER
108           [ EXTERNAL ] SECURITY DEFINER
109           Change whether the function is a security definer or not. The
110           key word EXTERNAL is ignored for SQL conformance. See CREATE
111           FUNCTION for more information about this capability.
112
113    PARALLEL
114           Change whether the function is deemed safe for parallelism. See
115           CREATE FUNCTION for details.
116
117    LEAKPROOF
118           Change whether the function is considered leakproof or not. See
119           CREATE FUNCTION for more information about this capability.
120
121    COST execution_cost
122           Change the estimated execution cost of the function. See CREATE
123           FUNCTION for more information.
124
125    ROWS result_rows
126           Change the estimated number of rows returned by a set-returning
127           function. See CREATE FUNCTION for more information.
128
129    SUPPORT support_function
130           Set or change the planner support function to use for this
131           function. See Section 36.11 for details. You must be superuser
132           to use this option.
133
134           This option cannot be used to remove the support function
135           altogether, since it must name a new support function. Use
136           CREATE OR REPLACE FUNCTION if you need to do that.
137
138    configuration_parameter
139           value
140           Add or change the assignment to be made to a configuration
141           parameter when the function is called. If value is DEFAULT or,
142           equivalently, RESET is used, the function-local setting is
143           removed, so that the function executes with the value present in
144           its environment. Use RESET ALL to clear all function-local
145           settings. SET FROM CURRENT saves the value of the parameter that
146           is current when ALTER FUNCTION is executed as the value to be
147           applied when the function is entered.
148
149           See SET and Chapter 19 for more information about allowed
150           parameter names and values.
151
152    RESTRICT
153           Ignored for conformance with the SQL standard.
154
155 Examples
156
157    To rename the function sqrt for type integer to square_root:
158 ALTER FUNCTION sqrt(integer) RENAME TO square_root;
159
160    To change the owner of the function sqrt for type integer to joe:
161 ALTER FUNCTION sqrt(integer) OWNER TO joe;
162
163    To change the schema of the function sqrt for type integer to maths:
164 ALTER FUNCTION sqrt(integer) SET SCHEMA maths;
165
166    To mark the function sqrt for type integer as being dependent on the
167    extension mathlib:
168 ALTER FUNCTION sqrt(integer) DEPENDS ON EXTENSION mathlib;
169
170    To adjust the search path that is automatically set for a function:
171 ALTER FUNCTION check_password(text) SET search_path = admin, pg_temp;
172
173    To disable automatic setting of search_path for a function:
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
179 Compatibility
180
181    This statement is partially compatible with the ALTER FUNCTION
182    statement in the SQL standard. The standard allows more properties of a
183    function to be modified, but does not provide the ability to rename a
184    function, make a function a security definer, attach configuration
185    parameter values to a function, or change the owner, schema, or
186    volatility of a function. The standard also requires the RESTRICT key
187    word, which is optional in PostgreSQL.
188
189 See Also
190
191    CREATE FUNCTION, DROP FUNCTION, ALTER PROCEDURE, ALTER ROUTINE