Home Explore Blog CI



postgresql

5th chunk of `doc/src/sgml/ref/alter_function.sgml`
7fa14ab82a3be906035971f625079f2a7316ab405cb089d70000000100000ddf
  <para>
        Add or change the assignment to be made to a configuration parameter
        when the function is called.  If
        <replaceable>value</replaceable> is <literal>DEFAULT</literal>
        or, equivalently, <literal>RESET</literal> is used, the function-local
        setting is removed, so that the function executes with the value
        present in its environment.  Use <literal>RESET
        ALL</literal> to clear all function-local settings.
        <literal>SET FROM CURRENT</literal> saves the value of the parameter that
        is current when <command>ALTER FUNCTION</command> is executed as the value
        to be applied when the function is entered.
       </para>

       <para>
        See <xref linkend="sql-set"/> and
        <xref linkend="runtime-config"/>
        for more information about allowed parameter names and values.
       </para>
      </listitem>
     </varlistentry>

   <varlistentry>
    <term><literal>RESTRICT</literal></term>

    <listitem>
     <para>
      Ignored for conformance with the SQL standard.
     </para>
    </listitem>
   </varlistentry>
  </variablelist>
 </refsect1>

 <refsect1>
  <title>Examples</title>

  <para>
   To rename the function <literal>sqrt</literal> for type
   <type>integer</type> to <literal>square_root</literal>:
<programlisting>
ALTER FUNCTION sqrt(integer) RENAME TO square_root;
</programlisting>
  </para>

  <para>
   To change the owner of the function <literal>sqrt</literal> for type
   <type>integer</type> to <literal>joe</literal>:
<programlisting>
ALTER FUNCTION sqrt(integer) OWNER TO joe;
</programlisting>
  </para>

  <para>
   To change the schema of the function <literal>sqrt</literal> for type
   <type>integer</type> to <literal>maths</literal>:
<programlisting>
ALTER FUNCTION sqrt(integer) SET SCHEMA maths;
</programlisting>
  </para>

  <para>
   To mark the function <literal>sqrt</literal> for type
   <type>integer</type> as being dependent on the extension
   <literal>mathlib</literal>:
<programlisting>
ALTER FUNCTION sqrt(integer) DEPENDS ON EXTENSION mathlib;
</programlisting>
  </para>

  <para>
   To adjust the search path that is automatically set for a function:
<programlisting>
ALTER FUNCTION check_password(text) SET search_path = admin, pg_temp;
</programlisting>
  </para>

  <para>
   To disable automatic setting of <varname>search_path</varname> for a function:
<programlisting>
ALTER FUNCTION check_password(text) RESET search_path;
</programlisting>
   The function will now execute with whatever search path is used by its
   caller.
  </para>
 </refsect1>

 <refsect1>
  <title>Compatibility</title>

  <para>
   This statement is partially compatible with the <command>ALTER
   FUNCTION</command> statement in the SQL standard. The standard allows more
   properties of a function to be modified, but does not provide the
   ability to rename a function, make a function a security definer,
   attach configuration parameter values to a function,
   or change the owner, schema, or volatility of a function. The standard also
   requires the <literal>RESTRICT</literal> key word, which is optional in
   <productname>PostgreSQL</productname>.
  </para>
 </refsect1>

 <refsect1>
  <title>See Also</title>

  <simplelist type="inline">
   <member><xref linkend="sql-createfunction"/></member>
   <member><xref linkend="sql-dropfunction"/></member>
   <member><xref linkend="sql-alterprocedure"/></member>
   <member><xref linkend="sql-alterroutine"/></member>
  </simplelist>
 </refsect1>
</refentry>

Title: ALTER FUNCTION - Examples and Compatibility
Summary
This section provides examples of using `ALTER FUNCTION` to rename a function, change its owner and schema, mark it as dependent on an extension, and adjust or disable its automatic search path. It also covers the SQL standard compatibility of the `ALTER FUNCTION` command, highlighting the differences between PostgreSQL and the standard, such as renaming, security definer, configuration parameters, owner, schema, volatility, and the optional `RESTRICT` keyword. Finally, it lists related commands like `CREATE FUNCTION`, `DROP FUNCTION`, `ALTER PROCEDURE`, and `ALTER ROUTINE`.