1ALTER FUNCTION() SQL Commands ALTER FUNCTION()
2
3
4
6 ALTER FUNCTION - change the definition of a function
7
8
10 ALTER FUNCTION name ( [ [ argmode ] [ argname ] argtype [, ...] ] )
11 action [, ... ] [ RESTRICT ]
12 ALTER FUNCTION name ( [ [ argmode ] [ argname ] argtype [, ...] ] )
13 RENAME TO new_name
14 ALTER FUNCTION name ( [ [ argmode ] [ argname ] argtype [, ...] ] )
15 OWNER TO new_owner
16 ALTER FUNCTION name ( [ [ argmode ] [ argname ] argtype [, ...] ] )
17 SET SCHEMA new_schema
18
19 where action is one of:
20
21 CALLED ON NULL INPUT | RETURNS NULL ON NULL INPUT | STRICT
22 IMMUTABLE | STABLE | VOLATILE
23 [ EXTERNAL ] SECURITY INVOKER | [ EXTERNAL ] SECURITY DEFINER
24
25
27 ALTER FUNCTION changes the definition of a function.
28
29 You must own the function to use ALTER FUNCTION. To change a func‐
30 tion's schema, you must also have CREATE privilege on the new schema.
31 To alter the owner, you must also be a direct or indirect member of the
32 new owning role, and that role must have CREATE privilege on the func‐
33 tion's schema. (These restrictions enforce that altering the owner
34 doesn't do anything you couldn't do by dropping and recreating the
35 function. However, a superuser can alter ownership of any function
36 anyway.)
37
39 name The name (optionally schema-qualified) of an existing function.
40
41 argmode
42 The mode of an argument: either IN, OUT, or INOUT. If omitted,
43 the default is IN. Note that ALTER FUNCTION does not actually
44 pay any attention to OUT arguments, since only the input argu‐
45 ments are needed to determine the function's identity. So it is
46 sufficient to list the IN and INOUT arguments.
47
48 argname
49 The name of an argument. Note that ALTER FUNCTION does not
50 actually pay any attention to argument names, since only the
51 argument data types are needed to determine the function's iden‐
52 tity.
53
54 argtype
55 The data type(s) of the function's arguments (optionally schema-
56 qualified), if any.
57
58 new_name
59 The new name of the function.
60
61 new_owner
62 The new owner of the function. Note that if the function is
63 marked SECURITY DEFINER, it will subsequently execute as the new
64 owner.
65
66 new_schema
67 The new schema for the function.
68
69 CALLED ON NULL INPUT
70
71 RETURNS NULL ON NULL INPUT
72
73 STRICT CALLED ON NULL INPUT changes the function so that it will be
74 invoked when some or all of its arguments are null. RETURNS NULL
75 ON NULL INPUT or STRICT changes the function so that it is not
76 invoked if any of its arguments are null; instead, a null result
77 is assumed automatically. See CREATE FUNCTION [create_func‐
78 tion(7)] for more information.
79
80 IMMUTABLE
81
82 STABLE
83
84 VOLATILE
85 Change the volatility of the function to the specified setting.
86 See CREATE FUNCTION [create_function(7)] for details.
87
88 [ EXTERNAL ] SECURITY INVOKER
89
90 [ EXTERNAL ] SECURITY DEFINER
91 Change whether the function is a security definer or not. The
92 key word EXTERNAL is ignored for SQL conformance. See CREATE
93 FUNCTION [create_function(7)] for more information about this
94 capability.
95
96 RESTRICT
97 Ignored for conformance with the SQL standard.
98
100 To rename the function sqrt for type integer to square_root:
101
102 ALTER FUNCTION sqrt(integer) RENAME TO square_root;
103
104
105 To change the owner of the function sqrt for type integer to joe:
106
107 ALTER FUNCTION sqrt(integer) OWNER TO joe;
108
109
110 To change the schema of the function sqrt for type integer to maths:
111
112 ALTER FUNCTION sqrt(integer) SET SCHEMA maths;
113
114
116 This statement is partially compatible with the ALTER FUNCTION state‐
117 ment in the SQL standard. The standard allows more properties of a
118 function to be modified, but does not provide the ability to rename a
119 function, make a function a security definer, or change the owner,
120 schema, or volatility of a function. The standard also requires the
121 RESTRICT key word, which is optional in PostgreSQL.
122
124 CREATE FUNCTION [create_function(7)], DROP FUNCTION [drop_function(l)]
125
126
127
128SQL - Language Statements 2008-06-08 ALTER FUNCTION()