<!--
doc/src/sgml/ref/create_procedure.sgml
PostgreSQL documentation
-->
<refentry id="sql-createprocedure">
<indexterm zone="sql-createprocedure">
<primary>CREATE PROCEDURE</primary>
</indexterm>
<refmeta>
<refentrytitle>CREATE PROCEDURE</refentrytitle>
<manvolnum>7</manvolnum>
<refmiscinfo>SQL - Language Statements</refmiscinfo>
</refmeta>
<refnamediv>
<refname>CREATE PROCEDURE</refname>
<refpurpose>define a new procedure</refpurpose>
</refnamediv>
<refsynopsisdiv>
<synopsis>
CREATE [ OR REPLACE ] PROCEDURE
<replaceable class="parameter">name</replaceable> ( [ [ <replaceable class="parameter">argmode</replaceable> ] [ <replaceable class="parameter">argname</replaceable> ] <replaceable class="parameter">argtype</replaceable> [ { DEFAULT | = } <replaceable class="parameter">default_expr</replaceable> ] [, ...] ] )
{ LANGUAGE <replaceable class="parameter">lang_name</replaceable>
| TRANSFORM { FOR TYPE <replaceable class="parameter">type_name</replaceable> } [, ... ]
| [ EXTERNAL ] SECURITY INVOKER | [ EXTERNAL ] SECURITY DEFINER
| SET <replaceable class="parameter">configuration_parameter</replaceable> { TO <replaceable class="parameter">value</replaceable> | = <replaceable class="parameter">value</replaceable> | FROM CURRENT }
| AS '<replaceable class="parameter">definition</replaceable>'
| AS '<replaceable class="parameter">obj_file</replaceable>', '<replaceable class="parameter">link_symbol</replaceable>'
| <replaceable class="parameter">sql_body</replaceable>
} ...
</synopsis>
</refsynopsisdiv>
<refsect1 id="sql-createprocedure-description">
<title>Description</title>
<para>
<command>CREATE PROCEDURE</command> defines a new procedure.
<command>CREATE OR REPLACE PROCEDURE</command> will either create a
new procedure, or replace an existing definition.
To be able to define a procedure, the user must have the
<literal>USAGE</literal> privilege on the language.
</para>
<para>
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 <firstterm>overloading</firstterm>).
</para>
<para>
To replace the current definition of an existing procedure, use
<command>CREATE OR REPLACE PROCEDURE</command>. 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).
</para>
<para>
When <command>CREATE OR REPLACE PROCEDURE</command> 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).
</para>
<para>
The user that creates the procedure becomes the owner of the procedure.
</para>
<para>
To be able to create a procedure, you must have <literal>USAGE</literal>
privilege on the argument types.
</para>
<para>
Refer to <xref linkend="xproc"/> for further information on writing
procedures.
</para>
</refsect1>
<refsect1>
<title>Parameters</title>
<variablelist>
<varlistentry>
<term><replaceable class="parameter">name</replaceable></term>
<listitem>
<para>
The name (optionally schema-qualified) of the procedure to create.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><replaceable class="parameter">argmode</replaceable></term>
<listitem>
<para>
The mode of an argument: <literal>IN</literal>, <literal>OUT</literal>,
<literal>INOUT</literal>, or <literal>VARIADIC</literal>.