Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9a4e4af

Browse files
committed
Doc: improve introductory information about procedures.
Clarify the discussion in "User-Defined Procedures", by laying outthe key differences between functions and procedures in a bulletedlist. Notably, this avoids burying the lede about procedures beingable to do transaction control. Make the back-link in the CREATEFUNCTION reference page more prominent, and add one in CREATEPROCEDURE.Per gripe from Guyren Howe. Thanks to David Johnston for discussion.Discussion:https://postgr.es/m/BYAPR03MB4903C53A8BB7EFF5EA289674A6949@BYAPR03MB4903.namprd03.prod.outlook.com
1 parentfe2b538 commit9a4e4af

File tree

3 files changed

+55
-20
lines changed

3 files changed

+55
-20
lines changed

‎doc/src/sgml/ref/create_function.sgml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ CREATE [ OR REPLACE ] FUNCTION
100100
To be able to create a function, you must have <literal>USAGE</literal>
101101
privilege on the argument types and the return type.
102102
</para>
103+
104+
<para>
105+
Refer to <xref linkend="xfunc"/> for further information on writing
106+
functions.
107+
</para>
103108
</refsect1>
104109

105110
<refsect1>
@@ -578,12 +583,6 @@ CREATE [ OR REPLACE ] FUNCTION
578583
</varlistentry>
579584

580585
</variablelist>
581-
582-
<para>
583-
Refer to <xref linkend="xfunc"/> for further information on writing
584-
functions.
585-
</para>
586-
587586
</refsect1>
588587

589588
<refsect1 id="sql-createfunction-overloading">
@@ -661,8 +660,7 @@ CREATE FUNCTION foo(int, int default 42) ...
661660
<title>Examples</title>
662661

663662
<para>
664-
Here are some trivial examples to help you get started. For more
665-
information and examples, see <xref linkend="xfunc"/>.
663+
Add two integers using a SQL function:
666664
<programlisting>
667665
CREATE FUNCTION add(integer, integer) RETURNS integer
668666
AS 'select $1 + $2;'

‎doc/src/sgml/ref/create_procedure.sgml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ CREATE [ OR REPLACE ] PROCEDURE
7676
To be able to create a procedure, you must have <literal>USAGE</literal>
7777
privilege on the argument types.
7878
</para>
79+
80+
<para>
81+
Refer to <xref linkend="xproc"/> for further information on writing
82+
procedures.
83+
</para>
7984
</refsect1>
8085

8186
<refsect1>

‎doc/src/sgml/xfunc.sgml

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -81,21 +81,53 @@
8181
</indexterm>
8282

8383
<para>
84-
A procedure is a database object similar to a function. The difference is
85-
that a procedure does not return a value, so there is no return type
86-
declaration. While a function is called as part of a query or DML
87-
command, a procedure is called in isolation using
88-
the <xref linkend="sql-call"/> command. If the CALL command is not
89-
part of an explicit transaction, a procedure in many server-side
90-
languages can commit, rollback, and begin new transactions during
91-
its execution, which is not possible in functions.
84+
A procedure is a database object similar to a function.
85+
The key differences are:
86+
87+
<itemizedlist>
88+
<listitem>
89+
<para>
90+
Procedures are defined with the <xref linkend="sql-createprocedure"/>
91+
command, not <command>CREATE FUNCTION</command>.
92+
</para>
93+
</listitem>
94+
<listitem>
95+
<para>
96+
Procedures do not return a function value; hence <command>CREATE
97+
PROCEDURE</command> lacks a <literal>RETURNS</literal> clause.
98+
However, procedures can instead return data to their callers via
99+
output parameters.
100+
</para>
101+
</listitem>
102+
<listitem>
103+
<para>
104+
While a function is called as part of a query or DML command, a
105+
procedure is called in isolation using
106+
the <xref linkend="sql-call"/> command.
107+
</para>
108+
</listitem>
109+
<listitem>
110+
<para>
111+
A procedure can commit or roll back transactions during its
112+
execution (then automatically beginning a new transaction), so long
113+
as the invoking <command>CALL</command> command is not part of an
114+
explicit transaction block. A function cannot do that.
115+
</para>
116+
</listitem>
117+
<listitem>
118+
<para>
119+
Certain function attributes, such as strictness, don't apply to
120+
procedures. Those attributes control how the function is
121+
used in a query, which isn't relevant to procedures.
122+
</para>
123+
</listitem>
124+
</itemizedlist>
92125
</para>
93126

94127
<para>
95-
The explanations on how to define user-defined functions in the rest of
96-
this chapter apply to procedures as well, except that
97-
the <xref linkend="sql-createprocedure"/> command is used instead, there is
98-
no return type, and some other features such as strictness don't apply.
128+
The explanations in the following sections about how to define
129+
user-defined functions apply to procedures as well, except for the
130+
points made above.
99131
</para>
100132

101133
<para>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp