1 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>36.4. User-Defined Procedures</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot" /><link rel="prev" href="xfunc.html" title="36.3. User-Defined Functions" /><link rel="next" href="xfunc-sql.html" title="36.5. Query Language (SQL) Functions" /></head><body id="docContent" class="container-fluid col-10"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">36.4. User-Defined Procedures</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="xfunc.html" title="36.3. User-Defined Functions">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="extend.html" title="Chapter 36. Extending SQL">Up</a></td><th width="60%" align="center">Chapter 36. Extending <acronym class="acronym">SQL</acronym></th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 18.0 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="xfunc-sql.html" title="36.5. Query Language (SQL) Functions">Next</a></td></tr></table><hr /></div><div class="sect1" id="XPROC"><div class="titlepage"><div><div><h2 class="title" style="clear: both">36.4. User-Defined Procedures <a href="#XPROC" class="id_link">#</a></h2></div></div></div><a id="id-1.8.3.7.2" class="indexterm"></a><p>
3 A procedure is a database object similar to a function.
4 The key differences are:
6 </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
7 Procedures are defined with
8 the <a class="link" href="sql-createprocedure.html" title="CREATE PROCEDURE"><code class="command">CREATE
9 PROCEDURE</code></a> command, not <code class="command">CREATE
11 </p></li><li class="listitem"><p>
12 Procedures do not return a function value; hence <code class="command">CREATE
13 PROCEDURE</code> lacks a <code class="literal">RETURNS</code> clause.
14 However, procedures can instead return data to their callers via
16 </p></li><li class="listitem"><p>
17 While a function is called as part of a query or DML command, a
18 procedure is called in isolation using
19 the <a class="link" href="sql-call.html" title="CALL"><code class="command">CALL</code></a> command.
20 </p></li><li class="listitem"><p>
21 A procedure can commit or roll back transactions during its
22 execution (then automatically beginning a new transaction), so long
23 as the invoking <code class="command">CALL</code> command is not part of an
24 explicit transaction block. A function cannot do that.
25 </p></li><li class="listitem"><p>
26 Certain function attributes, such as strictness, don't apply to
27 procedures. Those attributes control how the function is
28 used in a query, which isn't relevant to procedures.
29 </p></li></ul></div><p>
31 The explanations in the following sections about how to define
32 user-defined functions apply to procedures as well, except for the
35 Collectively, functions and procedures are also known
36 as <em class="firstterm">routines</em><a id="id-1.8.3.7.5.2" class="indexterm"></a>.
37 There are commands such as <a class="link" href="sql-alterroutine.html" title="ALTER ROUTINE"><code class="command">ALTER ROUTINE</code></a>
38 and <a class="link" href="sql-droproutine.html" title="DROP ROUTINE"><code class="command">DROP ROUTINE</code></a> that can operate on functions and
39 procedures without having to know which kind it is. Note, however, that
40 there is no <code class="literal">CREATE ROUTINE</code> command.
41 </p></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="xfunc.html" title="36.3. User-Defined Functions">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="extend.html" title="Chapter 36. Extending SQL">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="xfunc-sql.html" title="36.5. Query Language (SQL) Functions">Next</a></td></tr><tr><td width="40%" align="left" valign="top">36.3. User-Defined Functions </td><td width="20%" align="center"><a accesskey="h" href="index.html" title="PostgreSQL 18.0 Documentation">Home</a></td><td width="40%" align="right" valign="top"> 36.5. Query Language (<acronym class="acronym">SQL</acronym>) Functions</td></tr></table></div></body></html>