Skip to main content
The ALTER FUNCTION applies a to a .

Required privileges

Refer to the respective subcommands.

Synopsis

alter_func syntax diagram

Parameters

ParameterDescription
function\_with\_argtypesThe name of the function, with optional function arguments to alter.
For more information about the statement syntax, see . Additional parameters are documented for the respective subcommands.

Subcommands

SubcommandDescription
OWNER TOChange the owner of a function.
RENAME TOChange the name of a function.
SET SCHEMAChange the of a function.

OWNER TO

ALTER FUNCTION... OWNER TO is used to change the owner of a function.

Required privileges

  • To alter the owner of a function, the new owner must have CREATE privilege on the schema of the function.
  • To alter a function, a user must the function.
  • To alter a function, a user must have DROP on the schema of the function.

Parameters

ParameterDescription
role\_specThe role to set as the owner of the function.
For usage, see Synopsis.

RENAME TO

ALTER FUNCTION... RENAME TO changes the name of a function.

Required privileges

  • To alter a function, a user must the function.
  • To alter a function, a user must have DROP on the schema of the function.

Parameters

ParameterDescription
function\_new\_nameThe new name of the function.
For usage, see Synopsis.

SET SCHEMA

ALTER FUNCTION... SET SCHEMA changes the of a function.
CockroachDB supports SET SCHEMA as an .

Required privileges

  • To change the schema of a function, a user must have CREATE privilege on the new schema.
  • To alter a function, a user must the function.
  • To alter a function, a user must have DROP on the schema of the function.

Parameters

ParameterDescription
schema\_nameThe name of the new schema for the function.
For usage, see Synopsis.

Examples

Change the owner of a function

Suppose that the current owner of a sq function is root and you want to change the owner to a new user named max.
To verify that the owner is now max, run a join query against the pg_catalog.pg_proc and pg_catalog.pg_roles tables:

Rename a function

The following statement defines a function that computes the sum of two arguments:
The following statement renames the add function to sum:
The default schema for the function sum is public:
Since there is also a named sum, you must specify the public schema to invoke your user-defined sum function:
If you do not specify public when invoking a user-defined function, you will get an error when invoking a built-in function with the same name:

Change the schema of a function

Suppose you want to add the user-defined sum function from the preceding example to a new schema called cockroach_labs. By default, created in the database belong to the public schema:
If the new schema does not already exist, :
Then, change the function’s schema:

See also