gooderp18绿色标准版
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

168 行
16KB

  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 V1.79.1" /><link rel="prev" href="sql-alterforeigntable.html" title="ALTER FOREIGN TABLE" /><link rel="next" href="sql-altergroup.html" title="ALTER GROUP" /></head><body><div xmlns="http://www.w3.org/TR/xhtml1/transitional" 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 12.4 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></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">
  3. 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> [, ...] ] ) ]
  4. <em class="replaceable"><code>action</code></em> [ ... ] [ RESTRICT ]
  5. 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> [, ...] ] ) ]
  6. RENAME TO <em class="replaceable"><code>new_name</code></em>
  7. 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> [, ...] ] ) ]
  8. OWNER TO { <em class="replaceable"><code>new_owner</code></em> | CURRENT_USER | SESSION_USER }
  9. 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> [, ...] ] ) ]
  10. SET SCHEMA <em class="replaceable"><code>new_schema</code></em>
  11. 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> [, ...] ] ) ]
  12. DEPENDS ON EXTENSION <em class="replaceable"><code>extension_name</code></em>
  13. <span class="phrase">where <em class="replaceable"><code>action</code></em> is one of:</span>
  14. CALLED ON NULL INPUT | RETURNS NULL ON NULL INPUT | STRICT
  15. IMMUTABLE | STABLE | VOLATILE | [ NOT ] LEAKPROOF
  16. [ EXTERNAL ] SECURITY INVOKER | [ EXTERNAL ] SECURITY DEFINER
  17. PARALLEL { UNSAFE | RESTRICTED | SAFE }
  18. COST <em class="replaceable"><code>execution_cost</code></em>
  19. ROWS <em class="replaceable"><code>result_rows</code></em>
  20. SUPPORT <em class="replaceable"><code>support_function</code></em>
  21. SET <em class="replaceable"><code>configuration_parameter</code></em> { TO | = } { <em class="replaceable"><code>value</code></em> | DEFAULT }
  22. SET <em class="replaceable"><code>configuration_parameter</code></em> FROM CURRENT
  23. RESET <em class="replaceable"><code>configuration_parameter</code></em>
  24. RESET ALL
  25. </pre></div><div class="refsect1" id="id-1.9.3.14.5"><h2>Description</h2><p>
  26. <code class="command">ALTER FUNCTION</code> changes the definition of a
  27. function.
  28. </p><p>
  29. You must own the function to use <code class="command">ALTER FUNCTION</code>.
  30. To change a function's schema, you must also have <code class="literal">CREATE</code>
  31. privilege on the new schema.
  32. To alter the owner, you must also be a direct or indirect member of the new
  33. owning role, and that role must have <code class="literal">CREATE</code> privilege on
  34. the function's schema. (These restrictions enforce that altering the owner
  35. doesn't do anything you couldn't do by dropping and recreating the function.
  36. However, a superuser can alter ownership of any function anyway.)
  37. </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>
  38. The name (optionally schema-qualified) of an existing function. If no
  39. argument list is specified, the name must be unique in its schema.
  40. </p></dd><dt><span class="term"><em class="replaceable"><code>argmode</code></em></span></dt><dd><p>
  41. The mode of an argument: <code class="literal">IN</code>, <code class="literal">OUT</code>,
  42. <code class="literal">INOUT</code>, or <code class="literal">VARIADIC</code>.
  43. If omitted, the default is <code class="literal">IN</code>.
  44. Note that <code class="command">ALTER FUNCTION</code> does not actually pay
  45. any attention to <code class="literal">OUT</code> arguments, since only the input
  46. arguments are needed to determine the function's identity.
  47. So it is sufficient to list the <code class="literal">IN</code>, <code class="literal">INOUT</code>,
  48. and <code class="literal">VARIADIC</code> arguments.
  49. </p></dd><dt><span class="term"><em class="replaceable"><code>argname</code></em></span></dt><dd><p>
  50. The name of an argument.
  51. Note that <code class="command">ALTER FUNCTION</code> does not actually pay
  52. any attention to argument names, since only the argument data
  53. types are needed to determine the function's identity.
  54. </p></dd><dt><span class="term"><em class="replaceable"><code>argtype</code></em></span></dt><dd><p>
  55. The data type(s) of the function's arguments (optionally
  56. schema-qualified), if any.
  57. </p></dd><dt><span class="term"><em class="replaceable"><code>new_name</code></em></span></dt><dd><p>
  58. The new name of the function.
  59. </p></dd><dt><span class="term"><em class="replaceable"><code>new_owner</code></em></span></dt><dd><p>
  60. The new owner of the function. Note that if the function is
  61. marked <code class="literal">SECURITY DEFINER</code>, it will subsequently
  62. execute as the new owner.
  63. </p></dd><dt><span class="term"><em class="replaceable"><code>new_schema</code></em></span></dt><dd><p>
  64. The new schema for the function.
  65. </p></dd><dt><span class="term"><em class="replaceable"><code>extension_name</code></em></span></dt><dd><p>
  66. The name of the extension that the function is to depend on.
  67. </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 so
  68. that it will be invoked when some or all of its arguments are
  69. null. <code class="literal">RETURNS NULL ON NULL INPUT</code> or
  70. <code class="literal">STRICT</code> changes the function so that it is not
  71. invoked if any of its arguments are null; instead, a null result
  72. is assumed automatically. See <a class="xref" href="sql-createfunction.html" title="CREATE FUNCTION"><span class="refentrytitle">CREATE FUNCTION</span></a>
  73. for more information.
  74. </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>
  75. Change the volatility of the function to the specified setting.
  76. See <a class="xref" href="sql-createfunction.html" title="CREATE FUNCTION"><span class="refentrytitle">CREATE FUNCTION</span></a> for details.
  77. </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>
  78. Change whether the function is a security definer or not. The
  79. key word <code class="literal">EXTERNAL</code> is ignored for SQL
  80. conformance. See <a class="xref" href="sql-createfunction.html" title="CREATE FUNCTION"><span class="refentrytitle">CREATE FUNCTION</span></a> for more information about
  81. this capability.
  82. </p></dd><dt><span class="term"><code class="literal">PARALLEL</code></span></dt><dd><p>
  83. Change whether the function is deemed safe for parallelism.
  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">LEAKPROOF</code></span></dt><dd><p>
  86. Change whether the function is considered leakproof or not.
  87. See <a class="xref" href="sql-createfunction.html" title="CREATE FUNCTION"><span class="refentrytitle">CREATE FUNCTION</span></a> for more information about
  88. this capability.
  89. </p></dd><dt><span class="term"><code class="literal">COST</code> <em class="replaceable"><code>execution_cost</code></em></span></dt><dd><p>
  90. Change the estimated execution cost of the function.
  91. See <a class="xref" href="sql-createfunction.html" title="CREATE FUNCTION"><span class="refentrytitle">CREATE FUNCTION</span></a> for more information.
  92. </p></dd><dt><span class="term"><code class="literal">ROWS</code> <em class="replaceable"><code>result_rows</code></em></span></dt><dd><p>
  93. Change the estimated number of rows returned by a set-returning
  94. function. See <a class="xref" href="sql-createfunction.html" title="CREATE FUNCTION"><span class="refentrytitle">CREATE FUNCTION</span></a> for more information.
  95. </p></dd><dt><span class="term"><code class="literal">SUPPORT</code> <em class="replaceable"><code>support_function</code></em></span></dt><dd><p>
  96. Set or change the planner support function to use for this function.
  97. See <a class="xref" href="xfunc-optimization.html" title="37.11. Function Optimization Information">Section 37.11</a> for details. You must be
  98. superuser to use this option.
  99. </p><p>
  100. This option cannot be used to remove the support function altogether,
  101. since it must name a new support function. Use <code class="command">CREATE OR
  102. REPLACE FUNCTION</code> if you need to do that.
  103. </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>
  104. Add or change the assignment to be made to a configuration parameter
  105. when the function is called. If
  106. <em class="replaceable"><code>value</code></em> is <code class="literal">DEFAULT</code>
  107. or, equivalently, <code class="literal">RESET</code> is used, the function-local
  108. setting is removed, so that the function executes with the value
  109. present in its environment. Use <code class="literal">RESET
  110. ALL</code> to clear all function-local settings.
  111. <code class="literal">SET FROM CURRENT</code> saves the value of the parameter that
  112. is current when <code class="command">ALTER FUNCTION</code> is executed as the value
  113. to be applied when the function is entered.
  114. </p><p>
  115. See <a class="xref" href="sql-set.html" title="SET"><span class="refentrytitle">SET</span></a> and
  116. <a class="xref" href="runtime-config.html" title="Chapter 19. Server Configuration">Chapter 19</a>
  117. for more information about allowed parameter names and values.
  118. </p></dd><dt><span class="term"><code class="literal">RESTRICT</code></span></dt><dd><p>
  119. Ignored for conformance with the SQL standard.
  120. </p></dd></dl></div></div><div class="refsect1" id="id-1.9.3.14.7"><h2>Examples</h2><p>
  121. To rename the function <code class="literal">sqrt</code> for type
  122. <code class="type">integer</code> to <code class="literal">square_root</code>:
  123. </p><pre class="programlisting">
  124. ALTER FUNCTION sqrt(integer) RENAME TO square_root;
  125. </pre><p>
  126. </p><p>
  127. To change the owner of the function <code class="literal">sqrt</code> for type
  128. <code class="type">integer</code> to <code class="literal">joe</code>:
  129. </p><pre class="programlisting">
  130. ALTER FUNCTION sqrt(integer) OWNER TO joe;
  131. </pre><p>
  132. </p><p>
  133. To change the schema of the function <code class="literal">sqrt</code> for type
  134. <code class="type">integer</code> to <code class="literal">maths</code>:
  135. </p><pre class="programlisting">
  136. ALTER FUNCTION sqrt(integer) SET SCHEMA maths;
  137. </pre><p>
  138. </p><p>
  139. To mark the function <code class="literal">sqrt</code> for type
  140. <code class="type">integer</code> as being dependent on the extension
  141. <code class="literal">mathlib</code>:
  142. </p><pre class="programlisting">
  143. ALTER FUNCTION sqrt(integer) DEPENDS ON EXTENSION mathlib;
  144. </pre><p>
  145. </p><p>
  146. To adjust the search path that is automatically set for a function:
  147. </p><pre class="programlisting">
  148. ALTER FUNCTION check_password(text) SET search_path = admin, pg_temp;
  149. </pre><p>
  150. </p><p>
  151. To disable automatic setting of <code class="varname">search_path</code> for a function:
  152. </p><pre class="programlisting">
  153. ALTER FUNCTION check_password(text) RESET search_path;
  154. </pre><p>
  155. The function will now execute with whatever search path is used by its
  156. caller.
  157. </p></div><div class="refsect1" id="id-1.9.3.14.8"><h2>Compatibility</h2><p>
  158. This statement is partially compatible with the <code class="command">ALTER
  159. FUNCTION</code> statement in the SQL standard. The standard allows more
  160. properties of a function to be modified, but does not provide the
  161. ability to rename a function, make a function a security definer,
  162. attach configuration parameter values to a function,
  163. or change the owner, schema, or volatility of a function. The standard also
  164. requires the <code class="literal">RESTRICT</code> key word, which is optional in
  165. <span class="productname">PostgreSQL</span>.
  166. </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">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="sql-commands.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="sql-altergroup.html">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">Home</a></td><td width="40%" align="right" valign="top"> ALTER GROUP</td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1