3
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
4
<title>ALTER FUNCTION</title>
5
<link rel="stylesheet" href="stylesheet.css" type="text/css">
6
<link rev="made" href="pgsql-docs@postgresql.org">
7
<meta name="generator" content="DocBook XSL Stylesheets V1.70.0">
8
<link rel="start" href="index.html" title="PostgreSQL 8.1.4 Documentation">
9
<link rel="up" href="sql-commands.html" title="SQL Commands">
10
<link rel="prev" href="sql-alterdomain.html" title="ALTER DOMAIN">
11
<link rel="next" href="sql-altergroup.html" title="ALTER GROUP">
12
<link rel="copyright" href="ln-legalnotice.html" title="Legal Notice">
14
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="refentry" lang="en">
15
<a name="sql-alterfunction"></a><div class="titlepage"></div>
16
<div class="refnamediv">
18
<p>ALTER FUNCTION — change the definition of a function</p>
20
<a name="id741990"></a><div class="refsynopsisdiv">
22
<pre class="synopsis">ALTER FUNCTION <em class="replaceable"><code>name</code></em> ( [ [ <em class="replaceable"><code>argmode</code></em> ] [ <em class="replaceable"><code>argname</code></em> ] <em class="replaceable"><code>argtype</code></em> [, ...] ] )
23
<em class="replaceable"><code>action</code></em> [, ... ] [ RESTRICT ]
24
ALTER FUNCTION <em class="replaceable"><code>name</code></em> ( [ [ <em class="replaceable"><code>argmode</code></em> ] [ <em class="replaceable"><code>argname</code></em> ] <em class="replaceable"><code>argtype</code></em> [, ...] ] )
25
RENAME TO <em class="replaceable"><code>new_name</code></em>
26
ALTER FUNCTION <em class="replaceable"><code>name</code></em> ( [ [ <em class="replaceable"><code>argmode</code></em> ] [ <em class="replaceable"><code>argname</code></em> ] <em class="replaceable"><code>argtype</code></em> [, ...] ] )
27
OWNER TO <em class="replaceable"><code>new_owner</code></em>
28
ALTER FUNCTION <em class="replaceable"><code>name</code></em> ( [ [ <em class="replaceable"><code>argmode</code></em> ] [ <em class="replaceable"><code>argname</code></em> ] <em class="replaceable"><code>argtype</code></em> [, ...] ] )
29
SET SCHEMA <em class="replaceable"><code>new_schema</code></em>
31
where <em class="replaceable"><code>action</code></em> is one of:
33
CALLED ON NULL INPUT | RETURNS NULL ON NULL INPUT | STRICT
34
IMMUTABLE | STABLE | VOLATILE
35
[ EXTERNAL ] SECURITY INVOKER | [ EXTERNAL ] SECURITY DEFINER</pre>
37
<div class="refsect1" lang="en">
38
<a name="id742135"></a><h2>Description</h2>
39
<p> <code class="command">ALTER FUNCTION</code> changes the definition of a
42
<p> You must own the function to use <code class="command">ALTER FUNCTION</code>.
43
To change a function's schema, you must also have <code class="literal">CREATE</code>
44
privilege on the new schema.
45
To alter the owner, you must also be a direct or indirect member of the new
46
owning role, and that role must have <code class="literal">CREATE</code> privilege on
47
the function's schema. (These restrictions enforce that altering the owner
48
doesn't do anything you couldn't do by dropping and recreating the function.
49
However, a superuser can alter ownership of any function anyway.)
52
<div class="refsect1" lang="en">
53
<a name="id742179"></a><h2>Parameters</h2>
54
<div class="variablelist"><dl>
55
<dt><span class="term"><em class="replaceable"><code>name</code></em></span></dt>
56
<dd><p> The name (optionally schema-qualified) of an existing function.
58
<dt><span class="term"><em class="replaceable"><code>argmode</code></em></span></dt>
59
<dd><p> The mode of an argument: either <code class="literal">IN</code>, <code class="literal">OUT</code>,
60
or <code class="literal">INOUT</code>. If omitted, the default is <code class="literal">IN</code>.
61
Note that <code class="command">ALTER FUNCTION</code> does not actually pay
62
any attention to <code class="literal">OUT</code> arguments, since only the input
63
arguments are needed to determine the function's identity.
64
So it is sufficient to list the <code class="literal">IN</code> and <code class="literal">INOUT</code>
67
<dt><span class="term"><em class="replaceable"><code>argname</code></em></span></dt>
68
<dd><p> The name of an argument.
69
Note that <code class="command">ALTER FUNCTION</code> does not actually pay
70
any attention to argument names, since only the argument data
71
types are needed to determine the function's identity.
73
<dt><span class="term"><em class="replaceable"><code>argtype</code></em></span></dt>
74
<dd><p> The data type(s) of the function's arguments (optionally
75
schema-qualified), if any.
77
<dt><span class="term"><em class="replaceable"><code>new_name</code></em></span></dt>
78
<dd><p> The new name of the function.
80
<dt><span class="term"><em class="replaceable"><code>new_owner</code></em></span></dt>
81
<dd><p> The new owner of the function. Note that if the function is
82
marked <code class="literal">SECURITY DEFINER</code>, it will subsequently
83
execute as the new owner.
85
<dt><span class="term"><em class="replaceable"><code>new_schema</code></em></span></dt>
86
<dd><p> The new schema for the function.
89
<span xmlns="http://www.w3.org/TR/xhtml1/transitional" class="term"><code xmlns="" class="literal">CALLED ON NULL INPUT</code></span><br xmlns="http://www.w3.org/TR/xhtml1/transitional"></br><span xmlns="http://www.w3.org/TR/xhtml1/transitional" class="term"><code xmlns="" class="literal">RETURNS NULL ON NULL INPUT</code></span><br xmlns="http://www.w3.org/TR/xhtml1/transitional"></br><span class="term"><code class="literal">STRICT</code></span>
91
<dd><p> <code class="literal">CALLED ON NULL INPUT</code> changes the function so
92
that it will be invoked when some or all of its arguments are
93
null. <code class="literal">RETURNS NULL ON NULL INPUT</code> or
94
<code class="literal">STRICT</code> changes the function so that it is not
95
invoked if any of its arguments are null; instead, a null result
96
is assumed automatically. See <a href="sql-createfunction.html" title="CREATE FUNCTION"><span class="refentrytitle"><a name="sql-createfunction-title"></a>CREATE FUNCTION</span></a> for more information.
99
<span xmlns="http://www.w3.org/TR/xhtml1/transitional" class="term"><code xmlns="" class="literal">IMMUTABLE</code></span><br xmlns="http://www.w3.org/TR/xhtml1/transitional"></br><span xmlns="http://www.w3.org/TR/xhtml1/transitional" class="term"><code xmlns="" class="literal">STABLE</code></span><br xmlns="http://www.w3.org/TR/xhtml1/transitional"></br><span class="term"><code class="literal">VOLATILE</code></span>
101
<dd><p> Change the volatility of the function to the specified
102
setting. See <a href="sql-createfunction.html" title="CREATE FUNCTION"><span class="refentrytitle"><a name="sql-createfunction-title"></a>CREATE FUNCTION</span></a> for details.
105
<span xmlns="http://www.w3.org/TR/xhtml1/transitional" class="term"><code xmlns="" class="literal">[<span class="optional"> EXTERNAL </span>] SECURITY INVOKER</code></span><br xmlns="http://www.w3.org/TR/xhtml1/transitional"></br><span class="term"><code class="literal">[<span class="optional"> EXTERNAL </span>] SECURITY DEFINER</code></span>
107
<dd><p> Change whether the function is a security definer or not. The
108
key word <code class="literal">EXTERNAL</code> is ignored for SQL
109
conformance. See <a href="sql-createfunction.html" title="CREATE FUNCTION"><span class="refentrytitle"><a name="sql-createfunction-title"></a>CREATE FUNCTION</span></a> for more
110
information about this capability.
112
<dt><span class="term"><code class="literal">RESTRICT</code></span></dt>
113
<dd><p> Ignored for conformance with the SQL standard.
117
<div class="refsect1" lang="en">
118
<a name="id742485"></a><h2>Examples</h2>
119
<p> To rename the function <code class="literal">sqrt</code> for type
120
<code class="type">integer</code> to <code class="literal">square_root</code>:
122
<pre class="programlisting">ALTER FUNCTION sqrt(integer) RENAME TO square_root;</pre>
125
<p> To change the owner of the function <code class="literal">sqrt</code> for type
126
<code class="type">integer</code> to <code class="literal">joe</code>:
128
<pre class="programlisting">ALTER FUNCTION sqrt(integer) OWNER TO joe;</pre>
131
<p> To change the schema of the function <code class="literal">sqrt</code> for type
132
<code class="type">integer</code> to <code class="literal">maths</code>:
134
<pre class="programlisting">ALTER FUNCTION sqrt(integer) SET SCHEMA maths;</pre>
138
<div class="refsect1" lang="en">
139
<a name="id742571"></a><h2>Compatibility</h2>
140
<p> This statement is partially compatible with the <code class="command">ALTER
141
FUNCTION</code> statement in the SQL standard. The standard allows more
142
properties of a function to be modified, but does not provide the
143
ability to rename a function, make a function a security definer,
144
or change the owner, schema, or volatility of a function. The standard also
145
requires the <code class="literal">RESTRICT</code> key word, which is optional in
146
<span class="productname">PostgreSQL</span>.
149
<div class="refsect1" lang="en">
150
<a name="id742604"></a><h2>See Also</h2>
151
<span class="simplelist"><a href="sql-createfunction.html">CREATE FUNCTION</a>, <a href="sql-dropfunction.html">DROP FUNCTION</a></span>