CREATE PROCEDURE

A DDL 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

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

It is possible to create and call an empty procedure:

postgres=# CREATE PROCEDURE emptyproc() LANGUAGE SQL AS '';
CREATE PROCEDURE

postgres=# CALL emptyproc();
CALL

Categories

DDL, Functions and procedures, SQL command

See also

ALTER PROCEDURE, DROP PROCEDURE, CALL, CREATE FUNCTION