ALTER FUNCTION (SQL)
Alters a user-defined SQL function.
Syntax
ALTER FUNCTION... [[db-name.]schema.]function-name([arg-type1], ...) ... | SET SCHEMA new_schema ... | RENAME TO new_name ... | OWNER TO new_owner
Parameters
[db-name.]schema
|
Specifies a schema. If multiple schemas are defined in the database, include the schema name. For example: myschema.thisDbObject |
function-name |
The name of the SQL function to alter. Each function requires an accompanying argument, so you must specify the argument type for each function. |
RENAME TO new_name |
Specifies the new name of the function |
SET SCHEMA new_schema |
Specifies the new schema name where the function resides. |
OWNER TO new_owner |
Specifies the new owner of the function. |
Privileges
- Only a superuser or owner can alter a function.
- To rename a function (ALTER FUNCTION RENAME TO) the user must have USAGE and CREATE privilege on schema that contains the function.
- To specify a new schema (ALTER FUNCTION SET SCHEMA), the user must have USAGE privilege on schema that currently contains the function (old schema) and CREATE privilege on the schema to which the function will be moved (new schema).
Examples
This example renames a function called SQL_one to SQL_two:
=> ALTER FUNCTION SQL_one (int,int) RENAME TO SQL_two;
This example moves the SQL_two function to a new schema called macros
:
=> ALTER FUNCTION SQL_two (int) SET SCHEMA
macros;
This example assigns a new owner to SQL_two:
=> ALTER FUNCTION SQL_two (int, int) OWNER TO
user1;