development), start a new session.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><replaceable class="parameter">sql_body</replaceable></term>
<listitem>
<para>
The body of a <literal>LANGUAGE SQL</literal> procedure. This should
be a block
<programlisting>
BEGIN ATOMIC
<replaceable>statement</replaceable>;
<replaceable>statement</replaceable>;
...
<replaceable>statement</replaceable>;
END
</programlisting>
</para>
<para>
This is similar to writing the text of the procedure body as a string
constant (see <replaceable>definition</replaceable> above), but there
are some differences: This form only works for <literal>LANGUAGE
SQL</literal>, the string constant form works for all languages. This
form is parsed at procedure definition time, the string constant form is
parsed at execution time; therefore this form cannot support
polymorphic argument types and other constructs that are not resolvable
at procedure definition time. This form tracks dependencies between the
procedure and objects used in the procedure body, so <literal>DROP
... CASCADE</literal> will work correctly, whereas the form using
string literals may leave dangling procedures. Finally, this form is
more compatible with the SQL standard and other SQL implementations.
</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1 id="sql-createprocedure-notes">
<title>Notes</title>
<para>
See <xref linkend="sql-createfunction"/> for more details on function
creation that also apply to procedures.
</para>
<para>
Use <xref linkend="sql-call"/> to execute a procedure.
</para>
</refsect1>
<refsect1 id="sql-createprocedure-examples">
<title>Examples</title>
<para>
<programlisting>
CREATE PROCEDURE insert_data(a integer, b integer)
LANGUAGE SQL
AS $$
INSERT INTO tbl VALUES (a);
INSERT INTO tbl VALUES (b);
$$;
</programlisting>
or
<programlisting>
CREATE PROCEDURE insert_data(a integer, b integer)
LANGUAGE SQL
BEGIN ATOMIC
INSERT INTO tbl VALUES (a);
INSERT INTO tbl VALUES (b);
END;
</programlisting>
and call like this:
<programlisting>
CALL insert_data(1, 2);
</programlisting></para>
</refsect1>
<refsect1 id="sql-createprocedure-compat">
<title>Compatibility</title>
<para>
A <command>CREATE PROCEDURE</command> command is defined in the SQL
standard. The <productname>PostgreSQL</productname> implementation can be
used in a compatible way but has many extensions. For details see also
<xref linkend="sql-createfunction"/>.
</para>
</refsect1>
<refsect1>
<title>See Also</title>
<simplelist type="inline">
<member><xref linkend="sql-alterprocedure"/></member>
<member><xref linkend="sql-dropprocedure"/></member>
<member><xref linkend="sql-call"/></member>
<member><xref linkend="sql-createfunction"/></member>
</simplelist>
</refsect1>
</refentry>