2 .\" Title: ALTER FUNCTION
3 .\" Author: The PostgreSQL Global Development Group
4 .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
6 .\" Manual: PostgreSQL 18.0 Documentation
7 .\" Source: PostgreSQL 18.0
10 .TH "ALTER FUNCTION" "7" "2025" "PostgreSQL 18.0" "PostgreSQL 18.0 Documentation"
11 .\" -----------------------------------------------------------------
12 .\" * Define some portability stuff
13 .\" -----------------------------------------------------------------
14 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15 .\" http://bugs.debian.org/507673
16 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
17 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20 .\" -----------------------------------------------------------------
21 .\" * set default formatting
22 .\" -----------------------------------------------------------------
23 .\" disable hyphenation
25 .\" disable justification (adjust text to left margin only)
27 .\" -----------------------------------------------------------------
28 .\" * MAIN CONTENT STARTS HERE *
29 .\" -----------------------------------------------------------------
31 ALTER_FUNCTION \- change the definition of a function
35 ALTER FUNCTION \fIname\fR [ ( [ [ \fIargmode\fR ] [ \fIargname\fR ] \fIargtype\fR [, \&.\&.\&.] ] ) ]
36 \fIaction\fR [ \&.\&.\&. ] [ RESTRICT ]
37 ALTER FUNCTION \fIname\fR [ ( [ [ \fIargmode\fR ] [ \fIargname\fR ] \fIargtype\fR [, \&.\&.\&.] ] ) ]
38 RENAME TO \fInew_name\fR
39 ALTER FUNCTION \fIname\fR [ ( [ [ \fIargmode\fR ] [ \fIargname\fR ] \fIargtype\fR [, \&.\&.\&.] ] ) ]
40 OWNER TO { \fInew_owner\fR | CURRENT_ROLE | CURRENT_USER | SESSION_USER }
41 ALTER FUNCTION \fIname\fR [ ( [ [ \fIargmode\fR ] [ \fIargname\fR ] \fIargtype\fR [, \&.\&.\&.] ] ) ]
42 SET SCHEMA \fInew_schema\fR
43 ALTER FUNCTION \fIname\fR [ ( [ [ \fIargmode\fR ] [ \fIargname\fR ] \fIargtype\fR [, \&.\&.\&.] ] ) ]
44 [ NO ] DEPENDS ON EXTENSION \fIextension_name\fR
46 where \fIaction\fR is one of:
48 CALLED ON NULL INPUT | RETURNS NULL ON NULL INPUT | STRICT
49 IMMUTABLE | STABLE | VOLATILE
51 [ EXTERNAL ] SECURITY INVOKER | [ EXTERNAL ] SECURITY DEFINER
52 PARALLEL { UNSAFE | RESTRICTED | SAFE }
53 COST \fIexecution_cost\fR
54 ROWS \fIresult_rows\fR
55 SUPPORT \fIsupport_function\fR
56 SET \fIconfiguration_parameter\fR { TO | = } { \fIvalue\fR | DEFAULT }
57 SET \fIconfiguration_parameter\fR FROM CURRENT
58 RESET \fIconfiguration_parameter\fR
64 changes the definition of a function\&.
66 You must own the function to use
67 \fBALTER FUNCTION\fR\&. To change a function\*(Aqs schema, you must also have
69 privilege on the new schema\&. To alter the owner, you must be able to
71 to the new owning role, and that role must have
73 privilege on the function\*(Aqs schema\&. (These restrictions enforce that altering the owner doesn\*(Aqt do anything you couldn\*(Aqt do by dropping and recreating the function\&. However, a superuser can alter ownership of any function anyway\&.)
78 The name (optionally schema\-qualified) of an existing function\&. If no argument list is specified, the name must be unique in its schema\&.
83 The mode of an argument:
87 VARIADIC\&. If omitted, the default is
90 does not actually pay any attention to
92 arguments, since only the input arguments are needed to determine the function\*(Aqs identity\&. So it is sufficient to list the
101 The name of an argument\&. Note that
103 does not actually pay any attention to argument names, since only the argument data types are needed to determine the function\*(Aqs identity\&.
108 The data type(s) of the function\*(Aqs arguments (optionally schema\-qualified), if any\&.
113 The new name of the function\&.
118 The new owner of the function\&. Note that if the function is marked
119 SECURITY DEFINER, it will subsequently execute as the new owner\&.
124 The new schema for the function\&.
127 DEPENDS ON EXTENSION \fIextension_name\fR
129 NO DEPENDS ON EXTENSION \fIextension_name\fR
131 This form marks the function as dependent on the extension, or no longer dependent on that extension if
133 is specified\&. A function that\*(Aqs marked as dependent on an extension is dropped when the extension is dropped, even if
135 is not specified\&. A function can depend upon multiple extensions, and will be dropped when any one of those extensions is dropped\&.
140 RETURNS NULL ON NULL INPUT
145 changes the function so that it will be invoked when some or all of its arguments are null\&.
146 RETURNS NULL ON NULL INPUT
149 changes the function so that it is not invoked if any of its arguments are null; instead, a null result is assumed automatically\&. See
150 CREATE FUNCTION (\fBCREATE_FUNCTION\fR(7))
151 for more information\&.
160 Change the volatility of the function to the specified setting\&. See
161 CREATE FUNCTION (\fBCREATE_FUNCTION\fR(7))
165 [ EXTERNAL ] SECURITY INVOKER
167 [ EXTERNAL ] SECURITY DEFINER
169 Change whether the function is a security definer or not\&. The key word
171 is ignored for SQL conformance\&. See
172 CREATE FUNCTION (\fBCREATE_FUNCTION\fR(7))
173 for more information about this capability\&.
178 Change whether the function is deemed safe for parallelism\&. See
179 CREATE FUNCTION (\fBCREATE_FUNCTION\fR(7))
185 Change whether the function is considered leakproof or not\&. See
186 CREATE FUNCTION (\fBCREATE_FUNCTION\fR(7))
187 for more information about this capability\&.
190 COST \fIexecution_cost\fR
192 Change the estimated execution cost of the function\&. See
193 CREATE FUNCTION (\fBCREATE_FUNCTION\fR(7))
194 for more information\&.
197 ROWS \fIresult_rows\fR
199 Change the estimated number of rows returned by a set\-returning function\&. See
200 CREATE FUNCTION (\fBCREATE_FUNCTION\fR(7))
201 for more information\&.
204 SUPPORT \fIsupport_function\fR
206 Set or change the planner support function to use for this function\&. See
208 for details\&. You must be superuser to use this option\&.
210 This option cannot be used to remove the support function altogether, since it must name a new support function\&. Use
211 \fBCREATE OR REPLACE FUNCTION\fR
212 if you need to do that\&.
215 \fIconfiguration_parameter\fR
219 Add or change the assignment to be made to a configuration parameter when the function is called\&. If
225 is used, the function\-local setting is removed, so that the function executes with the value present in its environment\&. Use
227 to clear all function\-local settings\&.
229 saves the value of the parameter that is current when
231 is executed as the value to be applied when the function is entered\&.
237 for more information about allowed parameter names and values\&.
242 Ignored for conformance with the SQL standard\&.
246 To rename the function
257 ALTER FUNCTION sqrt(integer) RENAME TO square_root;
263 To change the owner of the function
274 ALTER FUNCTION sqrt(integer) OWNER TO joe;
280 To change the schema of the function
291 ALTER FUNCTION sqrt(integer) SET SCHEMA maths;
301 as being dependent on the extension
308 ALTER FUNCTION sqrt(integer) DEPENDS ON EXTENSION mathlib;
314 To adjust the search path that is automatically set for a function:
320 ALTER FUNCTION check_password(text) SET search_path = admin, pg_temp;
326 To disable automatic setting of
334 ALTER FUNCTION check_password(text) RESET search_path;
340 The function will now execute with whatever search path is used by its caller\&.
343 This statement is partially compatible with the
345 statement in the SQL standard\&. The standard allows more properties of a function to be modified, but does not provide the ability to rename a function, make a function a security definer, attach configuration parameter values to a function, or change the owner, schema, or volatility of a function\&. The standard also requires the
347 key word, which is optional in
350 CREATE FUNCTION (\fBCREATE_FUNCTION\fR(7)), DROP FUNCTION (\fBDROP_FUNCTION\fR(7)), ALTER PROCEDURE (\fBALTER_PROCEDURE\fR(7)), ALTER ROUTINE (\fBALTER_ROUTINE\fR(7))