Skip to content

ALTER PROCEDURE

Change the name, schema, or owner of a stored procedure.

ALTER PROCEDURE name()
{ RENAME TO new_name() |
  OWNER TO role |
  SET SCHEMA schema }

For example, rename a procedure:

premdb=# alter procedure proc1() rename to ybsp1;
ALTER PROCEDURE
premdb=# \dfp
                            List of functions
 Schema | Name  | Result data type | Argument data types |       Type       
--------+-------+------------------+---------------------+------------------
 public | ybsp1 | void             |                     | stored procedure
(1 row)

Now change the owner of the procedure:

premdb=# alter procedure ybsp1() owner to bobr;
ALTER PROCEDURE

Now change the schema of the procedure and list information about it with the \dfp command:

premdb=# alter procedure ybsp1() set schema prem;
ALTER PROCEDURE
premdb=# set schema 'prem';
SET
premdb=# \dfp
                            List of functions
 Schema | Name  | Result data type | Argument data types |       Type       
--------+-------+------------------+---------------------+------------------
 prem   | ybsp1 | void             |                     | stored procedure
(1 row)

Parent topic:SQL Commands