Contents
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
- PostgreSQL 12
- option
SUPPORT
added (commit 1fb57af9)
- option
- PostgreSQL 9.6
- PostgreSQL 8.3
- PostgreSQL 8.1
- PostgreSQL 8.0
ALTER FUNCTION ... OWNER TO ...
syntax added (commit 0adfa2c3)
- PostgreSQL 7.4
- added (commit b256f242)
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"
References
- PostgreSQL documentation: ALTER FUNCTION