ALTER FUNCTION

An SQL command for modifying a function

ALTER FUNCTION is a DDL command for modifying an existing function.

ALTER FUNCTION was added in PostgreSQL 7.4.

Usage

ALTER FUNCTION is used for updating a function's meta-data.

To change the definition of the function itself, use CREATE OR REPLACE FUNCTION.

Change history

Examples

Renaming a function with ALTER FUNCTION:

postgres=# ALTER FUNCTION foo() RENAME TO bar;
ALTER FUNCTION

The parentheses can be omitted if the function does not take any parameters and the function name is unique:

postgres=# ALTER FUNCTION bar RENAME TO foo;
ALTER FUNCTION

However if there is more than one function with the same name (but taking different parameters), the function's calling signature must be provided:

postgres=# ALTER FUNCTION bar rename to foo;
ERROR:  function name "bar" is not unique

postgres=# ALTER FUNCTION bar(int) RENAME TO foo;
ALTER FUNCTION

A function cannnot be renamed if another function already exists with the new name:

postgres=# ALTER FUNCTION bar(int) RENAME TO foo;
ERROR:  function foo(integer) already exists in schema "public"

Categories

DDL, Functions and procedures, SQL command

See also

CREATE FUNCTION, DROP FUNCTION, ALTER ROUTINE, ALTER PROCEDURE