Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lJmYa-0002FK-1F for pgsql-general@arkaria.postgresql.org; Wed, 10 Mar 2021 00:18:32 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lJmYY-0000n4-Qk for pgsql-general@arkaria.postgresql.org; Wed, 10 Mar 2021 00:18:30 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lJmYY-0000mw-Hw for pgsql-general@lists.postgresql.org; Wed, 10 Mar 2021 00:18:30 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lJmYW-0007iJ-Fa for pgsql-general@lists.postgresql.org; Wed, 10 Mar 2021 00:18:30 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 12A0ILap2052105; Tue, 9 Mar 2021 19:18:21 -0500 From: Tom Lane To: "David G. Johnston" cc: Peter Eisentraut , Guyren Howe , raf , Adrian Klaver , "Bysani, Ram" , "pgsql-general@lists.postgresql.org" Subject: Re: Need help with clarification on stored procedure support in PostGreSQL database In-reply-to: References: <29836c19-5321-7093-bc88-a82c6a497a36@aklaver.com> <20210308222228.gljiuauwdd4p3kxs@raf.org> <1932630.1615246316@sss.pgh.pa.us> <20210309005300.gdp2kjoy6bjwynaa@raf.org> <1994410.1615264880@sss.pgh.pa.us> <2043807.1615323448@sss.pgh.pa.us> <2047266.1615328509@sss.pgh.pa.us> <2050799.1615333843@sss.pgh.pa.us> Comments: In-reply-to "David G. Johnston" message dated "Tue, 09 Mar 2021 16:54:10 -0700" MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" Content-ID: <2052073.1615335460.0@sss.pgh.pa.us> Date: Tue, 09 Mar 2021 19:18:21 -0500 Message-ID: <2052104.1615335501@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk ------- =_aaaaaaaaaa0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2052073.1615335460.1@sss.pgh.pa.us> "David G. Johnston" writes: > On Tue, Mar 9, 2021 at 4:50 PM Tom Lane wrote: >> Would it be better >> to turn the para into a bulleted list, which we could introduce with >> "The key differences are:" ? > Indeed, reworking the rest of the paragraph around that introduction would > be much better. v2 attached. regards, tom lane ------- =_aaaaaaaaaa0 Content-Type: text/x-diff; name="improve-procedure-docs-2.patch"; charset="us-ascii" Content-ID: <2052073.1615335460.2@sss.pgh.pa.us> Content-Description: improve-procedure-docs-2.patch Content-Transfer-Encoding: quoted-printable diff --git a/doc/src/sgml/plpgsql.sgml b/doc/src/sgml/plpgsql.sgml index 9d41967ad3..9242c54329 100644 --- a/doc/src/sgml/plpgsql.sgml +++ b/doc/src/sgml/plpgsql.sgml @@ -1959,7 +1959,8 @@ SELECT * FROM get_available_flightid(CURRENT_DATE); or DO block can call a procedure using CALL. Output parameters are handled differently from the way that CALL works in plain - SQL. Each INOUT parameter of the procedure must + SQL. Each OUT or INOUT + parameter of the procedure must correspond to a variable in the CALL statement, a= nd whatever the procedure returns is assigned back to that variable aft= er it returns. For example: diff --git a/doc/src/sgml/ref/create_function.sgml b/doc/src/sgml/ref/crea= te_function.sgml index 3c1eaea651..f1001615f4 100644 --- a/doc/src/sgml/ref/create_function.sgml +++ b/doc/src/sgml/ref/create_function.sgml @@ -100,6 +100,11 @@ CREATE [ OR REPLACE ] FUNCTION To be able to create a function, you must have USAGE privilege on the argument types and the return type. + + + Refer to for further information on writing + functions. + = @@ -578,12 +583,6 @@ CREATE [ OR REPLACE ] FUNCTION = - - - Refer to for further information on writing - functions. - - = @@ -661,8 +660,7 @@ CREATE FUNCTION foo(int, int default 42) ... Examples = - Here are some trivial examples to help you get started. For more - information and examples, see . + Add two integers using a SQL function: CREATE FUNCTION add(integer, integer) RETURNS integer AS 'select $1 + $2;' diff --git a/doc/src/sgml/ref/create_procedure.sgml b/doc/src/sgml/ref/cre= ate_procedure.sgml index e258eca5ce..6dbc012719 100644 --- a/doc/src/sgml/ref/create_procedure.sgml +++ b/doc/src/sgml/ref/create_procedure.sgml @@ -76,6 +76,11 @@ CREATE [ OR REPLACE ] PROCEDURE To be able to create a procedure, you must have USAGE privilege on the argument types. + + + Refer to for further information on writing + procedures. + = diff --git a/doc/src/sgml/xfunc.sgml b/doc/src/sgml/xfunc.sgml index 2863f7c206..325ce9222a 100644 --- a/doc/src/sgml/xfunc.sgml +++ b/doc/src/sgml/xfunc.sgml @@ -81,21 +81,55 @@ = - A procedure is a database object similar to a function. The differen= ce is - that a procedure does not return a value, so there is no return type - declaration. While a function is called as part of a query or DML - command, a procedure is called in isolation using - the CALL command= . If the CALL command is not - part of an explicit transaction, a procedure in many server-side - languages can commit, rollback, and begin new transactions during - its execution, which is not possible in functions. + A procedure is a database object similar to a function. + The key differences are: + + + + + Procedures are defined with + the CREATE + PROCEDURE command, not CREATE + FUNCTION. + + + + + Procedures do not return a function value; hence CREATE + PROCEDURE lacks a RETURNS clause. + However, procedures can instead return data to their callers via + output parameters. + + + + + While a function is called as part of a query or DML command, a + procedure is called in isolation using + the CALL comm= and. + + + + + If the invoking CALL command is not part of an + explicit transaction block, a procedure can commit or roll back + transactions (then automatically beginning a new transaction) + during its execution, which a function cannot do. + + + + + Certain function attributes such as strictness don't apply to + procedures, because those attributes control how the function is + used in a query, which isn't relevant to procedures. + + + = - The explanations on how to define user-defined functions in the rest = of - this chapter apply to procedures as well, except that - the CREATE PROCEDURE command is used instead, there is - no return type, and some other features such as strictness don't appl= y. + The explanations in the following sections about how to define + user-defined functions apply to procedures as well, except for the + points made above. = ------- =_aaaaaaaaaa0--