]> begriffs open source - ai-pg/blob - full-docs/src/sgml/man7/ALTER_FUNCTION.7
PG 18 docs from https://ftp.postgresql.org/pub/source/v18.0/postgresql-18.0-docs...
[ai-pg] / full-docs / src / sgml / man7 / ALTER_FUNCTION.7
1 '\" t
2 .\"     Title: ALTER FUNCTION
3 .\"    Author: The PostgreSQL Global Development Group
4 .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
5 .\"      Date: 2025
6 .\"    Manual: PostgreSQL 18.0 Documentation
7 .\"    Source: PostgreSQL 18.0
8 .\"  Language: English
9 .\"
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 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18 .ie \n(.g .ds Aq \(aq
19 .el       .ds Aq '
20 .\" -----------------------------------------------------------------
21 .\" * set default formatting
22 .\" -----------------------------------------------------------------
23 .\" disable hyphenation
24 .nh
25 .\" disable justification (adjust text to left margin only)
26 .ad l
27 .\" -----------------------------------------------------------------
28 .\" * MAIN CONTENT STARTS HERE *
29 .\" -----------------------------------------------------------------
30 .SH "NAME"
31 ALTER_FUNCTION \- change the definition of a function
32 .SH "SYNOPSIS"
33 .sp
34 .nf
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
45
46 where \fIaction\fR is one of:
47
48     CALLED ON NULL INPUT | RETURNS NULL ON NULL INPUT | STRICT
49     IMMUTABLE | STABLE | VOLATILE
50     [ NOT ] LEAKPROOF
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
59     RESET ALL
60 .fi
61 .SH "DESCRIPTION"
62 .PP
63 \fBALTER FUNCTION\fR
64 changes the definition of a function\&.
65 .PP
66 You must own the function to use
67 \fBALTER FUNCTION\fR\&. To change a function\*(Aqs schema, you must also have
68 CREATE
69 privilege on the new schema\&. To alter the owner, you must be able to
70 SET ROLE
71 to the new owning role, and that role must have
72 CREATE
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\&.)
74 .SH "PARAMETERS"
75 .PP
76 \fIname\fR
77 .RS 4
78 The name (optionally schema\-qualified) of an existing function\&. If no argument list is specified, the name must be unique in its schema\&.
79 .RE
80 .PP
81 \fIargmode\fR
82 .RS 4
83 The mode of an argument:
84 IN,
85 OUT,
86 INOUT, or
87 VARIADIC\&. If omitted, the default is
88 IN\&. Note that
89 \fBALTER FUNCTION\fR
90 does not actually pay any attention to
91 OUT
92 arguments, since only the input arguments are needed to determine the function\*(Aqs identity\&. So it is sufficient to list the
93 IN,
94 INOUT, and
95 VARIADIC
96 arguments\&.
97 .RE
98 .PP
99 \fIargname\fR
100 .RS 4
101 The name of an argument\&. Note that
102 \fBALTER FUNCTION\fR
103 does not actually pay any attention to argument names, since only the argument data types are needed to determine the function\*(Aqs identity\&.
104 .RE
105 .PP
106 \fIargtype\fR
107 .RS 4
108 The data type(s) of the function\*(Aqs arguments (optionally schema\-qualified), if any\&.
109 .RE
110 .PP
111 \fInew_name\fR
112 .RS 4
113 The new name of the function\&.
114 .RE
115 .PP
116 \fInew_owner\fR
117 .RS 4
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\&.
120 .RE
121 .PP
122 \fInew_schema\fR
123 .RS 4
124 The new schema for the function\&.
125 .RE
126 .PP
127 DEPENDS ON EXTENSION \fIextension_name\fR
128 .br
129 NO DEPENDS ON EXTENSION \fIextension_name\fR
130 .RS 4
131 This form marks the function as dependent on the extension, or no longer dependent on that extension if
132 NO
133 is specified\&. A function that\*(Aqs marked as dependent on an extension is dropped when the extension is dropped, even if
134 CASCADE
135 is not specified\&. A function can depend upon multiple extensions, and will be dropped when any one of those extensions is dropped\&.
136 .RE
137 .PP
138 CALLED ON NULL INPUT
139 .br
140 RETURNS NULL ON NULL INPUT
141 .br
142 STRICT
143 .RS 4
144 CALLED 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
147 or
148 STRICT
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\&.
152 .RE
153 .PP
154 IMMUTABLE
155 .br
156 STABLE
157 .br
158 VOLATILE
159 .RS 4
160 Change the volatility of the function to the specified setting\&. See
161 CREATE FUNCTION (\fBCREATE_FUNCTION\fR(7))
162 for details\&.
163 .RE
164 .PP
165 [ EXTERNAL ] SECURITY INVOKER
166 .br
167 [ EXTERNAL ] SECURITY DEFINER
168 .RS 4
169 Change whether the function is a security definer or not\&. The key word
170 EXTERNAL
171 is ignored for SQL conformance\&. See
172 CREATE FUNCTION (\fBCREATE_FUNCTION\fR(7))
173 for more information about this capability\&.
174 .RE
175 .PP
176 PARALLEL
177 .RS 4
178 Change whether the function is deemed safe for parallelism\&. See
179 CREATE FUNCTION (\fBCREATE_FUNCTION\fR(7))
180 for details\&.
181 .RE
182 .PP
183 LEAKPROOF
184 .RS 4
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\&.
188 .RE
189 .PP
190 COST \fIexecution_cost\fR
191 .RS 4
192 Change the estimated execution cost of the function\&. See
193 CREATE FUNCTION (\fBCREATE_FUNCTION\fR(7))
194 for more information\&.
195 .RE
196 .PP
197 ROWS \fIresult_rows\fR
198 .RS 4
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\&.
202 .RE
203 .PP
204 SUPPORT \fIsupport_function\fR
205 .RS 4
206 Set or change the planner support function to use for this function\&. See
207 Section\ \&36.11
208 for details\&. You must be superuser to use this option\&.
209 .sp
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\&.
213 .RE
214 .PP
215 \fIconfiguration_parameter\fR
216 .br
217 \fIvalue\fR
218 .RS 4
219 Add or change the assignment to be made to a configuration parameter when the function is called\&. If
220 \fIvalue\fR
221 is
222 DEFAULT
223 or, equivalently,
224 RESET
225 is used, the function\-local setting is removed, so that the function executes with the value present in its environment\&. Use
226 RESET ALL
227 to clear all function\-local settings\&.
228 SET FROM CURRENT
229 saves the value of the parameter that is current when
230 \fBALTER FUNCTION\fR
231 is executed as the value to be applied when the function is entered\&.
232 .sp
233 See
234 \fBSET\fR(7)
235 and
236 Chapter\ \&19
237 for more information about allowed parameter names and values\&.
238 .RE
239 .PP
240 RESTRICT
241 .RS 4
242 Ignored for conformance with the SQL standard\&.
243 .RE
244 .SH "EXAMPLES"
245 .PP
246 To rename the function
247 sqrt
248 for type
249 integer
250 to
251 square_root:
252 .sp
253 .if n \{\
254 .RS 4
255 .\}
256 .nf
257 ALTER FUNCTION sqrt(integer) RENAME TO square_root;
258 .fi
259 .if n \{\
260 .RE
261 .\}
262 .PP
263 To change the owner of the function
264 sqrt
265 for type
266 integer
267 to
268 joe:
269 .sp
270 .if n \{\
271 .RS 4
272 .\}
273 .nf
274 ALTER FUNCTION sqrt(integer) OWNER TO joe;
275 .fi
276 .if n \{\
277 .RE
278 .\}
279 .PP
280 To change the schema of the function
281 sqrt
282 for type
283 integer
284 to
285 maths:
286 .sp
287 .if n \{\
288 .RS 4
289 .\}
290 .nf
291 ALTER FUNCTION sqrt(integer) SET SCHEMA maths;
292 .fi
293 .if n \{\
294 .RE
295 .\}
296 .PP
297 To mark the function
298 sqrt
299 for type
300 integer
301 as being dependent on the extension
302 mathlib:
303 .sp
304 .if n \{\
305 .RS 4
306 .\}
307 .nf
308 ALTER FUNCTION sqrt(integer) DEPENDS ON EXTENSION mathlib;
309 .fi
310 .if n \{\
311 .RE
312 .\}
313 .PP
314 To adjust the search path that is automatically set for a function:
315 .sp
316 .if n \{\
317 .RS 4
318 .\}
319 .nf
320 ALTER FUNCTION check_password(text) SET search_path = admin, pg_temp;
321 .fi
322 .if n \{\
323 .RE
324 .\}
325 .PP
326 To disable automatic setting of
327 \fIsearch_path\fR
328 for a function:
329 .sp
330 .if n \{\
331 .RS 4
332 .\}
333 .nf
334 ALTER FUNCTION check_password(text) RESET search_path;
335 .fi
336 .if n \{\
337 .RE
338 .\}
339 .sp
340 The function will now execute with whatever search path is used by its caller\&.
341 .SH "COMPATIBILITY"
342 .PP
343 This statement is partially compatible with the
344 \fBALTER FUNCTION\fR
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
346 RESTRICT
347 key word, which is optional in
348 PostgreSQL\&.
349 .SH "SEE ALSO"
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))