ALTER ROUTINE โ change the definition of a routine (aggregate, function, or procedure).
| Use Case | Command | Description |
|---|---|---|
| ๐ Rename a routine | ALTER ROUTINE foo(integer) RENAME TO bar; | Rename the routine with matching argument types. |
| ๐ฆ Change owner | ALTER ROUTINE foo(integer) OWNER TO alice; | Transfer ownership of the routine. |
| ๐๏ธ Move to a schema | ALTER ROUTINE foo(integer) SET SCHEMA new_schema; | Relocate the routine to another schema. |
| ๐ Security definer | ALTER ROUTINE foo(integer) SECURITY DEFINER; | Execute with the privileges of the routine owner. |
| ๐ Set volatility | ALTER ROUTINE foo(integer) IMMUTABLE; | Label as IMMUTABLE, STABLE, or VOLATILE. |
| โ๏ธ Change cost | ALTER ROUTINE foo(integer) COST 100; | Adjust estimated execution cost. |
| ๐ Estimated rows | ALTER ROUTINE foo(integer) ROWS 1000; | Set approximate number of rows returned by the routine. |
| ๐งต Parallel safety | ALTER ROUTINE foo(integer) PARALLEL SAFE; | Control whether parallel execution is allowed. |
| ๐ ๏ธ Configuration | ALTER ROUTINE foo(integer) SET work_mem = '4MB'; | Set session-level parameters for the routine. |
| ๐ Extension dependency | ALTER ROUTINE foo(integer) DEPENDS ON EXTENSION ext; | Mark routine as dependent (or NOT) on an extension. |
ALTER ROUTINE name [ ( [ [ argmode ] [ argname ] argtype [, ...] ] ) ]
action [ ... ] [ RESTRICT ]
ALTER ROUTINE name [ ( [ [ argmode ] [ argname ] argtype [, ...] ] ) ]
RENAME TO new_name
ALTER ROUTINE name [ ( [ [ argmode ] [ argname ] argtype [, ...] ] ) ]
OWNER TO { new_owner | CURRENT_ROLE | CURRENT_USER | SESSION_USER }
ALTER ROUTINE name [ ( [ [ argmode ] [ argname ] argtype [, ...] ] ) ]
SET SCHEMA new_schema
ALTER ROUTINE name [ ( [ [ argmode ] [ argname ] argtype [, ...] ] ) ]
[ NO ] DEPENDS ON EXTENSION extension_name
where action is one of:
ALTER ROUTINE changes the definition of a routine, which can be an aggregate function, a normal function, or a procedure. See under ALTER AGGREGATE (7), ALTER FUNCTION (7), and ALTER PROCEDURE (7) for the description of the parameters, more examples, and further details.
To rename the routine foo for type integer to foobar:
ALTER ROUTINE foo(integer) RENAME TO foobar;
This command will work independent of whether foo is an aggregate, function, or procedure.
This statement is partially compatible with the ALTER ROUTINE statement in the SQL standard. See under ALTER FUNCTION (7) and ALTER PROCEDURE (7) for more details. Allowing routine names to refer to aggregate functions is a PostgreSQL extension.
ALTER AGGREGATE (7), ALTER FUNCTION (7), ALTER PROCEDURE (7), DROP ROUTINE (7)
Note that there is no CREATE ROUTINE command.
Generated by phpman v4.9.26-5-g7740029 Author: Che Dong Under GNU General Public License
2026-08-24 03:45 @216.73.216.102
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)