1 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>ALTER PROCEDURE</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot" /><link rel="prev" href="sql-alterpolicy.html" title="ALTER POLICY" /><link rel="next" href="sql-alterpublication.html" title="ALTER PUBLICATION" /></head><body id="docContent" class="container-fluid col-10"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">ALTER PROCEDURE</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="sql-alterpolicy.html" title="ALTER POLICY">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="sql-commands.html" title="SQL Commands">Up</a></td><th width="60%" align="center">SQL Commands</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 18.0 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="sql-alterpublication.html" title="ALTER PUBLICATION">Next</a></td></tr></table><hr /></div><div class="refentry" id="SQL-ALTERPROCEDURE"><div class="titlepage"></div><a id="id-1.9.3.24.1" class="indexterm"></a><div class="refnamediv"><h2><span class="refentrytitle">ALTER PROCEDURE</span></h2><p>ALTER PROCEDURE — change the definition of a procedure</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
3 ALTER PROCEDURE <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> [, ...] ] ) ]
4 <em class="replaceable"><code>action</code></em> [ ... ] [ RESTRICT ]
5 ALTER PROCEDURE <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> [, ...] ] ) ]
6 RENAME TO <em class="replaceable"><code>new_name</code></em>
7 ALTER PROCEDURE <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> [, ...] ] ) ]
8 OWNER TO { <em class="replaceable"><code>new_owner</code></em> | CURRENT_ROLE | CURRENT_USER | SESSION_USER }
9 ALTER PROCEDURE <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> [, ...] ] ) ]
10 SET SCHEMA <em class="replaceable"><code>new_schema</code></em>
11 ALTER PROCEDURE <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> [, ...] ] ) ]
12 [ NO ] DEPENDS ON EXTENSION <em class="replaceable"><code>extension_name</code></em>
14 <span class="phrase">where <em class="replaceable"><code>action</code></em> is one of:</span>
16 [ EXTERNAL ] SECURITY INVOKER | [ EXTERNAL ] SECURITY DEFINER
17 SET <em class="replaceable"><code>configuration_parameter</code></em> { TO | = } { <em class="replaceable"><code>value</code></em> | DEFAULT }
18 SET <em class="replaceable"><code>configuration_parameter</code></em> FROM CURRENT
19 RESET <em class="replaceable"><code>configuration_parameter</code></em>
21 </pre></div><div class="refsect1" id="id-1.9.3.24.5"><h2>Description</h2><p>
22 <code class="command">ALTER PROCEDURE</code> changes the definition of a
25 You must own the procedure to use <code class="command">ALTER PROCEDURE</code>.
26 To change a procedure's schema, you must also have <code class="literal">CREATE</code>
27 privilege on the new schema.
28 To alter the owner, you must be able to <code class="literal">SET ROLE</code> to the
29 new owning role, and that role must have <code class="literal">CREATE</code>
30 privilege on the procedure's schema.
31 (These restrictions enforce that altering the owner
32 doesn't do anything you couldn't do by dropping and recreating the procedure.
33 However, a superuser can alter ownership of any procedure anyway.)
34 </p></div><div class="refsect1" id="id-1.9.3.24.6"><h2>Parameters</h2><div class="variablelist"><dl class="variablelist"><dt><span class="term"><em class="replaceable"><code>name</code></em></span></dt><dd><p>
35 The name (optionally schema-qualified) of an existing procedure. If no
36 argument list is specified, the name must be unique in its schema.
37 </p></dd><dt><span class="term"><em class="replaceable"><code>argmode</code></em></span></dt><dd><p>
38 The mode of an argument: <code class="literal">IN</code>, <code class="literal">OUT</code>,
39 <code class="literal">INOUT</code>, or <code class="literal">VARIADIC</code>. If omitted,
40 the default is <code class="literal">IN</code>.
41 </p></dd><dt><span class="term"><em class="replaceable"><code>argname</code></em></span></dt><dd><p>
42 The name of an argument.
43 Note that <code class="command">ALTER PROCEDURE</code> does not actually pay
44 any attention to argument names, since only the argument data
45 types are used to determine the procedure's identity.
46 </p></dd><dt><span class="term"><em class="replaceable"><code>argtype</code></em></span></dt><dd><p>
47 The data type(s) of the procedure's arguments (optionally
48 schema-qualified), if any.
49 See <a class="xref" href="sql-dropprocedure.html" title="DROP PROCEDURE"><span class="refentrytitle">DROP PROCEDURE</span></a> for the details of how
50 the procedure is looked up using the argument data type(s).
51 </p></dd><dt><span class="term"><em class="replaceable"><code>new_name</code></em></span></dt><dd><p>
52 The new name of the procedure.
53 </p></dd><dt><span class="term"><em class="replaceable"><code>new_owner</code></em></span></dt><dd><p>
54 The new owner of the procedure. Note that if the procedure is
55 marked <code class="literal">SECURITY DEFINER</code>, it will subsequently
56 execute as the new owner.
57 </p></dd><dt><span class="term"><em class="replaceable"><code>new_schema</code></em></span></dt><dd><p>
58 The new schema for the procedure.
59 </p></dd><dt><span class="term"><em class="replaceable"><code>extension_name</code></em></span></dt><dd><p>
60 This form marks the procedure as dependent on the extension, or no longer
61 dependent on the extension if <code class="literal">NO</code> is specified.
62 A procedure that's marked as dependent on an extension is dropped when the
63 extension is dropped, even if cascade is not specified.
64 A procedure can depend upon multiple extensions, and will be dropped when
65 any one of those extensions is dropped.
66 </p></dd><dt><span class="term"><code class="literal">[<span class="optional"> EXTERNAL </span>] SECURITY INVOKER</code><br /></span><span class="term"><code class="literal">[<span class="optional"> EXTERNAL </span>] SECURITY DEFINER</code></span></dt><dd><p>
67 Change whether the procedure is a security definer or not. The
68 key word <code class="literal">EXTERNAL</code> is ignored for SQL
69 conformance. See <a class="xref" href="sql-createprocedure.html" title="CREATE PROCEDURE"><span class="refentrytitle">CREATE PROCEDURE</span></a> for more information about
71 </p></dd><dt><span class="term"><em class="replaceable"><code>configuration_parameter</code></em><br /></span><span class="term"><em class="replaceable"><code>value</code></em></span></dt><dd><p>
72 Add or change the assignment to be made to a configuration parameter
73 when the procedure is called. If
74 <em class="replaceable"><code>value</code></em> is <code class="literal">DEFAULT</code>
75 or, equivalently, <code class="literal">RESET</code> is used, the procedure-local
76 setting is removed, so that the procedure executes with the value
77 present in its environment. Use <code class="literal">RESET
78 ALL</code> to clear all procedure-local settings.
79 <code class="literal">SET FROM CURRENT</code> saves the value of the parameter that
80 is current when <code class="command">ALTER PROCEDURE</code> is executed as the value
81 to be applied when the procedure is entered.
83 See <a class="xref" href="sql-set.html" title="SET"><span class="refentrytitle">SET</span></a> and
84 <a class="xref" href="runtime-config.html" title="Chapter 19. Server Configuration">Chapter 19</a>
85 for more information about allowed parameter names and values.
86 </p></dd><dt><span class="term"><code class="literal">RESTRICT</code></span></dt><dd><p>
87 Ignored for conformance with the SQL standard.
88 </p></dd></dl></div></div><div class="refsect1" id="id-1.9.3.24.7"><h2>Examples</h2><p>
89 To rename the procedure <code class="literal">insert_data</code> with two arguments
90 of type <code class="type">integer</code> to <code class="literal">insert_record</code>:
91 </p><pre class="programlisting">
92 ALTER PROCEDURE insert_data(integer, integer) RENAME TO insert_record;
95 To change the owner of the procedure <code class="literal">insert_data</code> with
96 two arguments of type <code class="type">integer</code> to <code class="literal">joe</code>:
97 </p><pre class="programlisting">
98 ALTER PROCEDURE insert_data(integer, integer) OWNER TO joe;
101 To change the schema of the procedure <code class="literal">insert_data</code> with
102 two arguments of type <code class="type">integer</code>
103 to <code class="literal">accounting</code>:
104 </p><pre class="programlisting">
105 ALTER PROCEDURE insert_data(integer, integer) SET SCHEMA accounting;
108 To mark the procedure <code class="literal">insert_data(integer, integer)</code> as
109 being dependent on the extension <code class="literal">myext</code>:
110 </p><pre class="programlisting">
111 ALTER PROCEDURE insert_data(integer, integer) DEPENDS ON EXTENSION myext;
114 To adjust the search path that is automatically set for a procedure:
115 </p><pre class="programlisting">
116 ALTER PROCEDURE check_password(text) SET search_path = admin, pg_temp;
119 To disable automatic setting of <code class="varname">search_path</code> for a procedure:
120 </p><pre class="programlisting">
121 ALTER PROCEDURE check_password(text) RESET search_path;
123 The procedure will now execute with whatever search path is used by its
125 </p></div><div class="refsect1" id="id-1.9.3.24.8"><h2>Compatibility</h2><p>
126 This statement is partially compatible with the <code class="command">ALTER
127 PROCEDURE</code> statement in the SQL standard. The standard allows more
128 properties of a procedure to be modified, but does not provide the
129 ability to rename a procedure, make a procedure a security definer,
130 attach configuration parameter values to a procedure,
131 or change the owner, schema, or volatility of a procedure. The standard also
132 requires the <code class="literal">RESTRICT</code> key word, which is optional in
133 <span class="productname">PostgreSQL</span>.
134 </p></div><div class="refsect1" id="id-1.9.3.24.9"><h2>See Also</h2><span class="simplelist"><a class="xref" href="sql-createprocedure.html" title="CREATE PROCEDURE"><span class="refentrytitle">CREATE PROCEDURE</span></a>, <a class="xref" href="sql-dropprocedure.html" title="DROP PROCEDURE"><span class="refentrytitle">DROP PROCEDURE</span></a>, <a class="xref" href="sql-alterfunction.html" title="ALTER FUNCTION"><span class="refentrytitle">ALTER FUNCTION</span></a>, <a class="xref" href="sql-alterroutine.html" title="ALTER ROUTINE"><span class="refentrytitle">ALTER ROUTINE</span></a></span></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="sql-alterpolicy.html" title="ALTER POLICY">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="sql-commands.html" title="SQL Commands">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="sql-alterpublication.html" title="ALTER PUBLICATION">Next</a></td></tr><tr><td width="40%" align="left" valign="top">ALTER POLICY </td><td width="20%" align="center"><a accesskey="h" href="index.html" title="PostgreSQL 18.0 Documentation">Home</a></td><td width="40%" align="right" valign="top"> ALTER PUBLICATION</td></tr></table></div></body></html>