Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes15kdownloads
sql-alterfunction.html174 linesDownload Raw Back to html
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 FUNCTION</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-alterforeigntable.html" title="ALTER FOREIGN TABLE" /><link rel="next" href="sql-altergroup.html" title="ALTER GROUP" /></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 FUNCTION</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="sql-alterforeigntable.html" title="ALTER FOREIGN TABLE">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 16.3 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="sql-altergroup.html" title="ALTER GROUP">Next</a></td></tr></table><hr /></div><div class="refentry" id="SQL-ALTERFUNCTION"><div class="titlepage"></div><a id="id-1.9.3.14.1" class="indexterm"></a><div class="refnamediv"><h2><span class="refentrytitle">ALTER FUNCTION</span></h2><p>ALTER FUNCTION — change the definition of a function</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">3ALTER 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> [, ...] ] ) ]4    <em class="replaceable"><code>action</code></em> [ ... ] [ RESTRICT ]5ALTER 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> [, ...] ] ) ]6    RENAME TO <em class="replaceable"><code>new_name</code></em>7ALTER 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> [, ...] ] ) ]8    OWNER TO { <em class="replaceable"><code>new_owner</code></em> | CURRENT_ROLE | CURRENT_USER | SESSION_USER }9ALTER 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> [, ...] ] ) ]10    SET SCHEMA <em class="replaceable"><code>new_schema</code></em>11ALTER 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> [, ...] ] ) ]12    [ NO ] DEPENDS ON EXTENSION <em class="replaceable"><code>extension_name</code></em>13 14<span class="phrase">where <em class="replaceable"><code>action</code></em> is one of:</span>15 16    CALLED ON NULL INPUT | RETURNS NULL ON NULL INPUT | STRICT17    IMMUTABLE | STABLE | VOLATILE18    [ NOT ] LEAKPROOF19    [ EXTERNAL ] SECURITY INVOKER | [ EXTERNAL ] SECURITY DEFINER20    PARALLEL { UNSAFE | RESTRICTED | SAFE }21    COST <em class="replaceable"><code>execution_cost</code></em>22    ROWS <em class="replaceable"><code>result_rows</code></em>23    SUPPORT <em class="replaceable"><code>support_function</code></em>24    SET <em class="replaceable"><code>configuration_parameter</code></em> { TO | = } { <em class="replaceable"><code>value</code></em> | DEFAULT }25    SET <em class="replaceable"><code>configuration_parameter</code></em> FROM CURRENT26    RESET <em class="replaceable"><code>configuration_parameter</code></em>27    RESET ALL28</pre></div><div class="refsect1" id="id-1.9.3.14.5"><h2>Description</h2><p>29   <code class="command">ALTER FUNCTION</code> changes the definition of a30   function.31  </p><p>32   You must own the function to use <code class="command">ALTER FUNCTION</code>.33   To change a function's schema, you must also have <code class="literal">CREATE</code>34   privilege on the new schema.  To alter the owner, you must be able to35   <code class="literal">SET ROLE</code> to the new owning role, and that role must36   have <code class="literal">CREATE</code> privilege on37   the function's schema.  (These restrictions enforce that altering the owner38   doesn't do anything you couldn't do by dropping and recreating the function.39   However, a superuser can alter ownership of any function anyway.)40  </p></div><div class="refsect1" id="id-1.9.3.14.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>41      The name (optionally schema-qualified) of an existing function.  If no42      argument list is specified, the name must be unique in its schema.43     </p></dd><dt><span class="term"><em class="replaceable"><code>argmode</code></em></span></dt><dd><p>44      The mode of an argument: <code class="literal">IN</code>, <code class="literal">OUT</code>,45      <code class="literal">INOUT</code>, or <code class="literal">VARIADIC</code>.46      If omitted, the default is <code class="literal">IN</code>.47      Note that <code class="command">ALTER FUNCTION</code> does not actually pay48      any attention to <code class="literal">OUT</code> arguments, since only the input49      arguments are needed to determine the function's identity.50      So it is sufficient to list the <code class="literal">IN</code>, <code class="literal">INOUT</code>,51      and <code class="literal">VARIADIC</code> arguments.52     </p></dd><dt><span class="term"><em class="replaceable"><code>argname</code></em></span></dt><dd><p>53      The name of an argument.54      Note that <code class="command">ALTER FUNCTION</code> does not actually pay55      any attention to argument names, since only the argument data56      types are needed to determine the function's identity.57     </p></dd><dt><span class="term"><em class="replaceable"><code>argtype</code></em></span></dt><dd><p>58      The data type(s) of the function's arguments (optionally59      schema-qualified), if any.60     </p></dd><dt><span class="term"><em class="replaceable"><code>new_name</code></em></span></dt><dd><p>61      The new name of the function.62     </p></dd><dt><span class="term"><em class="replaceable"><code>new_owner</code></em></span></dt><dd><p>63      The new owner of the function.  Note that if the function is64      marked <code class="literal">SECURITY DEFINER</code>, it will subsequently65      execute as the new owner.66     </p></dd><dt><span class="term"><em class="replaceable"><code>new_schema</code></em></span></dt><dd><p>67      The new schema for the function.68     </p></dd><dt><span class="term"><code class="literal">DEPENDS ON EXTENSION <em class="replaceable"><code>extension_name</code></em></code><br /></span><span class="term"><code class="literal">NO DEPENDS ON EXTENSION <em class="replaceable"><code>extension_name</code></em></code></span></dt><dd><p>69      This form marks the function as dependent on the extension, or no longer70      dependent on that extension if <code class="literal">NO</code> is specified.71      A function that's marked as dependent on an extension is dropped when the72      extension is dropped, even if <code class="literal">CASCADE</code> is not specified.73      A function can depend upon multiple extensions, and will be dropped when74      any one of those extensions is dropped.75     </p></dd><dt><span class="term"><code class="literal">CALLED ON NULL INPUT</code><br /></span><span class="term"><code class="literal">RETURNS NULL ON NULL INPUT</code><br /></span><span class="term"><code class="literal">STRICT</code></span></dt><dd><p><code class="literal">CALLED ON NULL INPUT</code> changes the function so76       that it will be invoked when some or all of its arguments are77       null. <code class="literal">RETURNS NULL ON NULL INPUT</code> or78       <code class="literal">STRICT</code> changes the function so that it is not79       invoked if any of its arguments are null; instead, a null result80       is assumed automatically.  See <a class="xref" href="sql-createfunction.html" title="CREATE FUNCTION"><span class="refentrytitle">CREATE FUNCTION</span></a>81       for more information.82      </p></dd><dt><span class="term"><code class="literal">IMMUTABLE</code><br /></span><span class="term"><code class="literal">STABLE</code><br /></span><span class="term"><code class="literal">VOLATILE</code></span></dt><dd><p>83       Change the volatility of the function to the specified setting.84       See <a class="xref" href="sql-createfunction.html" title="CREATE FUNCTION"><span class="refentrytitle">CREATE FUNCTION</span></a> for details.85      </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>86      Change whether the function is a security definer or not. The87      key word <code class="literal">EXTERNAL</code> is ignored for SQL88      conformance. See <a class="xref" href="sql-createfunction.html" title="CREATE FUNCTION"><span class="refentrytitle">CREATE FUNCTION</span></a> for more information about89      this capability.90     </p></dd><dt><span class="term"><code class="literal">PARALLEL</code></span></dt><dd><p>91      Change whether the function is deemed safe for parallelism.92      See <a class="xref" href="sql-createfunction.html" title="CREATE FUNCTION"><span class="refentrytitle">CREATE FUNCTION</span></a> for details.93     </p></dd><dt><span class="term"><code class="literal">LEAKPROOF</code></span></dt><dd><p>94      Change whether the function is considered leakproof or not.95      See <a class="xref" href="sql-createfunction.html" title="CREATE FUNCTION"><span class="refentrytitle">CREATE FUNCTION</span></a> for more information about96      this capability.97     </p></dd><dt><span class="term"><code class="literal">COST</code> <em class="replaceable"><code>execution_cost</code></em></span></dt><dd><p>98       Change the estimated execution cost of the function.99       See <a class="xref" href="sql-createfunction.html" title="CREATE FUNCTION"><span class="refentrytitle">CREATE FUNCTION</span></a> for more information.100      </p></dd><dt><span class="term"><code class="literal">ROWS</code> <em class="replaceable"><code>result_rows</code></em></span></dt><dd><p>101       Change the estimated number of rows returned by a set-returning102       function.  See <a class="xref" href="sql-createfunction.html" title="CREATE FUNCTION"><span class="refentrytitle">CREATE FUNCTION</span></a> for more information.103      </p></dd><dt><span class="term"><code class="literal">SUPPORT</code> <em class="replaceable"><code>support_function</code></em></span></dt><dd><p>104      Set or change the planner support function to use for this function.105      See <a class="xref" href="xfunc-optimization.html" title="38.11. Function Optimization Information">Section 38.11</a> for details.  You must be106      superuser to use this option.107     </p><p>108      This option cannot be used to remove the support function altogether,109      since it must name a new support function.  Use <code class="command">CREATE OR110      REPLACE FUNCTION</code> if you need to do that.111     </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>112        Add or change the assignment to be made to a configuration parameter113        when the function is called.  If114        <em class="replaceable"><code>value</code></em> is <code class="literal">DEFAULT</code>115        or, equivalently, <code class="literal">RESET</code> is used, the function-local116        setting is removed, so that the function executes with the value117        present in its environment.  Use <code class="literal">RESET118        ALL</code> to clear all function-local settings.119        <code class="literal">SET FROM CURRENT</code> saves the value of the parameter that120        is current when <code class="command">ALTER FUNCTION</code> is executed as the value121        to be applied when the function is entered.122       </p><p>123        See <a class="xref" href="sql-set.html" title="SET"><span class="refentrytitle">SET</span></a> and124        <a class="xref" href="runtime-config.html" title="Chapter 20. Server Configuration">Chapter 20</a>125        for more information about allowed parameter names and values.126       </p></dd><dt><span class="term"><code class="literal">RESTRICT</code></span></dt><dd><p>127      Ignored for conformance with the SQL standard.128     </p></dd></dl></div></div><div class="refsect1" id="id-1.9.3.14.7"><h2>Examples</h2><p>129   To rename the function <code class="literal">sqrt</code> for type130   <code class="type">integer</code> to <code class="literal">square_root</code>:131</p><pre class="programlisting">132ALTER FUNCTION sqrt(integer) RENAME TO square_root;133</pre><p>134  </p><p>135   To change the owner of the function <code class="literal">sqrt</code> for type136   <code class="type">integer</code> to <code class="literal">joe</code>:137</p><pre class="programlisting">138ALTER FUNCTION sqrt(integer) OWNER TO joe;139</pre><p>140  </p><p>141   To change the schema of the function <code class="literal">sqrt</code> for type142   <code class="type">integer</code> to <code class="literal">maths</code>:143</p><pre class="programlisting">144ALTER FUNCTION sqrt(integer) SET SCHEMA maths;145</pre><p>146  </p><p>147   To mark the function <code class="literal">sqrt</code> for type148   <code class="type">integer</code> as being dependent on the extension149   <code class="literal">mathlib</code>:150</p><pre class="programlisting">151ALTER FUNCTION sqrt(integer) DEPENDS ON EXTENSION mathlib;152</pre><p>153  </p><p>154   To adjust the search path that is automatically set for a function:155</p><pre class="programlisting">156ALTER FUNCTION check_password(text) SET search_path = admin, pg_temp;157</pre><p>158  </p><p>159   To disable automatic setting of <code class="varname">search_path</code> for a function:160</p><pre class="programlisting">161ALTER FUNCTION check_password(text) RESET search_path;162</pre><p>163   The function will now execute with whatever search path is used by its164   caller.165  </p></div><div class="refsect1" id="id-1.9.3.14.8"><h2>Compatibility</h2><p>166   This statement is partially compatible with the <code class="command">ALTER167   FUNCTION</code> statement in the SQL standard. The standard allows more168   properties of a function to be modified, but does not provide the169   ability to rename a function, make a function a security definer,170   attach configuration parameter values to a function,171   or change the owner, schema, or volatility of a function. The standard also172   requires the <code class="literal">RESTRICT</code> key word, which is optional in173   <span class="productname">PostgreSQL</span>.174  </p></div><div class="refsect1" id="id-1.9.3.14.9"><h2>See Also</h2><span class="simplelist"><a class="xref" href="sql-createfunction.html" title="CREATE FUNCTION"><span class="refentrytitle">CREATE FUNCTION</span></a>, <a class="xref" href="sql-dropfunction.html" title="DROP FUNCTION"><span class="refentrytitle">DROP FUNCTION</span></a>, <a class="xref" href="sql-alterprocedure.html" title="ALTER PROCEDURE"><span class="refentrytitle">ALTER PROCEDURE</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-alterforeigntable.html" title="ALTER FOREIGN TABLE">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-altergroup.html" title="ALTER GROUP">Next</a></td></tr><tr><td width="40%" align="left" valign="top">ALTER FOREIGN TABLE </td><td width="20%" align="center"><a accesskey="h" href="index.html" title="PostgreSQL 16.3 Documentation">Home</a></td><td width="40%" align="right" valign="top"> ALTER GROUP</td></tr></table></div></body></html>
codekingpro/portable-devtools · Team Ai