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 1lJjQG-0002vs-R9 for pgsql-general@arkaria.postgresql.org; Tue, 09 Mar 2021 20:57:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lJjQF-0008QK-EW for pgsql-general@arkaria.postgresql.org; Tue, 09 Mar 2021 20:57:43 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lJjQF-0008QD-6x for pgsql-general@lists.postgresql.org; Tue, 09 Mar 2021 20:57:43 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lJjQ8-0003px-Ga for pgsql-general@lists.postgresql.org; Tue, 09 Mar 2021 20:57:42 +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 129KvS842043808; Tue, 9 Mar 2021 15:57:28 -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> Comments: In-reply-to "David G. Johnston" message dated "Mon, 08 Mar 2021 21:47:43 -0700" MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" Content-ID: <2043761.1615323385.0@sss.pgh.pa.us> Date: Tue, 09 Mar 2021 15:57:28 -0500 Message-ID: <2043807.1615323448@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: <2043761.1615323385.1@sss.pgh.pa.us> "David G. Johnston" writes: > On Mon, Mar 8, 2021 at 9:41 PM Tom Lane wrote: >> Guyren Howe writes: >>> This seems like an important consideration. I've spent 10 minutes >>> searching the documentation for PG 11 and can't find where it is >>> documented. Perhaps it should be made more prominent? >> https://www.postgresql.org/docs/current/xproc.html > CREATE FUNCTION links into 37.3 but CREATE PROCEDURE doesn't link into 37.4 > Even if this may not be sufficient it seems reasonable to at least remain > consistent. I suspect most people start at CREATE, not "Server > Programming". Yeah, fair point, and it also seems like we ought to give those links more prominence. In the attached proposed patch, I put them into the introductory section of the reference pages. I also failed to resist the temptation to do some wordsmithing in 38.4 ... regards, tom lane ------- =_aaaaaaaaaa0 Content-Type: text/x-diff; name="improve-procedure-docs.patch"; charset="us-ascii" Content-ID: <2043761.1615323385.2@sss.pgh.pa.us> Content-Description: improve-procedure-docs.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..d18a5ab5d2 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. - - = diff --git a/doc/src/sgml/ref/create_procedure.sgml b/doc/src/sgml/ref/cre= ate_procedure.sgml index e258eca5ce..b4d2e5920c 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. + = @@ -328,6 +333,10 @@ $$; = CALL insert_data(1, 2); + + + For more information and examples, see . + = diff --git a/doc/src/sgml/xfunc.sgml b/doc/src/sgml/xfunc.sgml index 2863f7c206..c492348261 100644 --- a/doc/src/sgml/xfunc.sgml +++ b/doc/src/sgml/xfunc.sgml @@ -81,19 +81,19 @@ = - A procedure is a database object similar to a function. The differen= ce is + A procedure is a database object similar to a function. One 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. + 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. = - The explanations on how to define user-defined functions in the rest = of - this chapter apply to procedures as well, except that + The explanations in the following sections about how to define + user-defined functions 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. ------- =_aaaaaaaaaa0--