Contents
CREATE PROCEDURE
An SQL command for defining a new procedure
CREATE PROCEDURE
is a DDL command for defining a new procedure.
CREATE PROCEDURE
was added in PostgreSQL 11.
Change history
- PostgreSQL 14
- support for SQL-standard function bodies when creating SQL functions (commit e717a9a1)
- PostgreSQL 11
- added (commit e4128ee7)
Examples
Basic usage example for CREATE PROCEDURE
:
postgres=# CREATE PROCEDURE foo() LANGUAGE SQL AS 'SELECT pg_reload_conf()'; CREATE PROCEDURE postgres=# CALL foo(); CALL
It is not possible to create a procedure with the same name and arguments as an existing function:
postgres=# CREATE PROCEDURE foo(int) LANGUAGE SQL AS 'SELECT 1'; ERROR: function "foo" already exists with same argument types
It is possible to create functions and procedures with the same name but different argument types:
postgres=# \df List of functions Schema | Name | Result data type | Argument data types | Type --------+------+------------------+---------------------+------ public | foo | | | proc public | foo | integer | integer | func (2 rows)
It is possible to create and call an empty procedure:
postgres=# CREATE PROCEDURE emptyproc() LANGUAGE SQL AS ''; CREATE PROCEDURE postgres=# CALL emptyproc(); CALL
References
- PostgreSQL documentation: CREATE PROCEDURE