info > CREATE_PROCEDURE

PROCEDURE(7) PostgreSQL 14.23 Documentation CREATE PROCEDURE(7)

πŸ“› NAME

CREATE_PROCEDURE - define a new procedure

πŸš€ Quick Reference

Use Case Command Description
πŸ“ Create a simple SQL procedure CREATE PROCEDURE insert_data(a integer, b integer) LANGUAGE SQL AS $$ ... $$; Defines a procedure with two integer parameters that inserts rows.
πŸ”„ Create or replace a procedure CREATE OR REPLACE PROCEDURE proc_name(...) LANGUAGE plpgsql AS $$ ... $$; Replaces an existing procedure definition (keeps ownership/permissions).
πŸ”’ Create a SECURITY DEFINER procedure CREATE PROCEDURE ... SECURITY DEFINER LANGUAGE sql ... Procedure runs with owner privileges; cannot use transaction control.
βš™οΈ Set a configuration parameter CREATE PROCEDURE ... SET search_path TO public ... Sets a parameter value for the procedure session; restored on exit.
πŸ”— Use SQL standard body (BEGIN ATOMIC) CREATE PROCEDURE ... LANGUAGE SQL BEGIN ATOMIC ... END; Parsed at definition time, tracks dependencies, SQL standard compatible.

πŸ“‹ SYNOPSIS

CREATE [ OR REPLACE ] PROCEDURE
    name ( [ [ argmode ] [ argname ] argtype [ { DEFAULT | = } default_expr ] [, ...] ] )
  { LANGUAGE lang_name
    | TRANSFORM { FOR TYPE type_name } [, ... ]
    | [ EXTERNAL ] SECURITY INVOKER | [ EXTERNAL ] SECURITY DEFINER
    | SET configuration_parameter { TO value | = value | FROM CURRENT }
    | AS 'definition'
    | AS 'obj_file', 'link_symbol'
    | sql_body
  } ...

πŸ“– DESCRIPTION

CREATE PROCEDURE defines a new procedure. CREATE OR REPLACE PROCEDURE will either create a new procedure, or replace an existing definition. To be able to define a procedure, the user must have the USAGE privilege on the language.

If a schema name is included, then the procedure is created in the specified schema. Otherwise it is created in the current schema. The name of the new procedure must not match any existing procedure or function with the same input argument types in the same schema. However, procedures and functions of different argument types can share a name (this is called overloading).

To replace the current definition of an existing procedure, use CREATE OR REPLACE PROCEDURE. It is not possible to change the name or argument types of a procedure this way (if you tried, you would actually be creating a new, distinct procedure).

When CREATE OR REPLACE PROCEDURE is used to replace an existing procedure, the ownership and permissions of the procedure do not change. All other procedure properties are assigned the values specified or implied in the command. You must own the procedure to replace it (this includes being a member of the owning role).

The user that creates the procedure becomes the owner of the procedure.

To be able to create a procedure, you must have USAGE privilege on the argument types.

Refer to Section 38.4 for further information on writing procedures.

βš™οΈ PARAMETERS

πŸ“ NOTES

See CREATE FUNCTION for more details on function creation that also apply to procedures.

Use CALL(7) to execute a procedure.

πŸ’‘ EXAMPLES

CREATE PROCEDURE insert_data(a integer, b integer)
LANGUAGE SQL
AS $$
INSERT INTO tbl VALUES (a);
INSERT INTO tbl VALUES (b);
$$;

or

CREATE PROCEDURE insert_data(a integer, b integer)
LANGUAGE SQL
BEGIN ATOMIC
  INSERT INTO tbl VALUES (a);
  INSERT INTO tbl VALUES (b);
END;

and call like this:

CALL insert_data(1, 2);

πŸ”— COMPATIBILITY

A CREATE PROCEDURE command is defined in the SQL standard. The PostgreSQL implementation can be used in a compatible way but has many extensions. For details see also CREATE FUNCTION.

πŸ“š SEE ALSO

ALTER PROCEDURE, DROP PROCEDURE, CALL(7), CREATE FUNCTION

PostgreSQL 14.23 2026 CREATE PROCEDURE(7)

CREATE_PROCEDURE
πŸ“› NAME πŸš€ Quick Reference πŸ“‹ SYNOPSIS πŸ“– DESCRIPTION βš™οΈ PARAMETERS πŸ“ NOTES πŸ’‘ EXAMPLES πŸ”— COMPATIBILITY πŸ“š SEE ALSO

Generated by phpman v4.9.26-5-g7740029 Author: Che Dong Under GNU General Public License
2026-08-16 09:47 @2600:1f28:365:80b0:7cb9:fb:26c1:e368
CrawledBy CCBot/2.0 (https://commoncrawl.org/faq/)
Valid XHTML 1.0 Transitional!Valid CSS!