pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedNeed help with clarification on stored procedure support in PostGreSQL database
20+ messages / 7 participants
[nested] [flat]
Commits from this thread:
2021-03-10 227338b00d 74207b8fc5 e0fcde7f74 9a4e4af420 Doc: improve introductory information about procedures.
* Need help with clarification on stored procedure support in PostGreSQL database
@ 2021-03-07 18:48 Bysani, Ram <rbysani@informatica.com>
0 siblings, 2 replies; 20+ messages in thread
From: Bysani, Ram @ 2021-03-07 18:48 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>; security@postgresql.org <security@postgresql.org>
PostgreSQL version: 11.11
Operating system: Linux 64 bit
Description:
Greetings
We have found posts on several forums that Stored Procedures are not supported in PostGreSQL databasel.
We looked at the documentation but it is not clear when Stored Procedure support was added. We are aware that Functions are supported.
Please provide details / clarify if Stored Procedures are available in versions 11.x, 12.x, 13.x Please also confirm when it was actually added.
https://www.postgresql.org/docs/
Thanks for your time
Regards
Ram Bysani
^ permalink raw reply [nested|flat] 20+ messages in thread
* Re: Need help with clarification on stored procedure support in PostGreSQL database
@ 2021-03-07 18:52 David G. Johnston <david.g.johnston@gmail.com>
parent: Bysani, Ram <rbysani@informatica.com>
1 sibling, 0 replies; 20+ messages in thread
From: David G. Johnston @ 2021-03-07 18:52 UTC (permalink / raw)
To: Bysani, Ram <rbysani@informatica.com>; +Cc: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>; security@postgresql.org <security@postgresql.org>
On Sun, Mar 7, 2021 at 11:49 AM Bysani, Ram <rbysani@informatica.com> wrote:
> Please provide details / clarify if Stored Procedures are available in
> versions 11.x, 12.x, 13.x Please also confirm when it was actually added.
>
> https://www.postgresql.org/docs/
>
https://www.postgresql.org/docs/current/sql-createprocedure.html
David J.
^ permalink raw reply [nested|flat] 20+ messages in thread
* Re: Need help with clarification on stored procedure support in PostGreSQL database
@ 2021-03-07 19:01 Adrian Klaver <adrian.klaver@aklaver.com>
parent: Bysani, Ram <rbysani@informatica.com>
1 sibling, 1 reply; 20+ messages in thread
From: Adrian Klaver @ 2021-03-07 19:01 UTC (permalink / raw)
To: Bysani, Ram <rbysani@informatica.com>; pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>; security@postgresql.org <security@postgresql.org>
On 3/7/21 10:48 AM, Bysani, Ram wrote:
> PostgreSQL version: 11.11
>
> Operating system: Linux 64 bit
>
> Description:
>
> Greetings
>
> We have found posts on several forums that Stored Procedures are not
> supported in PostGreSQL databasel.
>
> We looked at the documentation but it is not clear when Stored Procedure
> support was added. We are aware that Functions are supported.
>
> Please provide details / clarify if Stored Procedures are available in
> versions 11.x, 12.x, 13.x Please also confirm when it was actually added.
>
> https://www.postgresql.org/docs/ <https://www.postgresql.org/docs/;
>
> Thanks for your time
Go to page David Johnson posted:
https://www.postgresql.org/docs/current/sql-createprocedure.html
and look at 'Supported Versions:' at top of page.
>
> Regards
>
> Ram Bysani
>
--
Adrian Klaver
adrian.klaver@aklaver.com
^ permalink raw reply [nested|flat] 20+ messages in thread
* Re: Need help with clarification on stored procedure support in PostGreSQL database
@ 2021-03-08 22:22 raf <raf@raf.org>
parent: Adrian Klaver <adrian.klaver@aklaver.com>
0 siblings, 1 reply; 20+ messages in thread
From: raf @ 2021-03-08 22:22 UTC (permalink / raw)
To: Adrian Klaver <adrian.klaver@aklaver.com>; +Cc: Bysani, Ram <rbysani@informatica.com>; pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
On Sun, Mar 07, 2021 at 11:01:07AM -0800, Adrian Klaver <adrian.klaver@aklaver.com> wrote:
> On 3/7/21 10:48 AM, Bysani, Ram wrote:
> > PostgreSQL version: 11.11
> >
> > Operating system: Linux 64 bit
> >
> > Description:
> >
> > Greetings
> >
> > We have found posts on several forums that Stored Procedures are not
> > supported in PostGreSQL databasel.
> >
> > We looked at the documentation but it is not clear when Stored Procedure
> > support was added. We are aware that Functions are supported.
> >
> > Please provide details / clarify if Stored Procedures are available in
> > versions 11.x, 12.x, 13.x Please also confirm when it was actually
> > added.
> >
> > https://www.postgresql.org/docs/ <https://www.postgresql.org/docs/;
> >
> > Thanks for your time
>
> Go to page David Johnson posted:
>
> https://www.postgresql.org/docs/current/sql-createprocedure.html
>
> and look at 'Supported Versions:' at top of page.
>
> > Regards
> > Ram Bysani
>
> --
> Adrian Klaver
> adrian.klaver@aklaver.com
Is there any important different between a stored procedure and
a stored function that returns void? I've been using functions
for everything but calling them procedures in my head (even though
most of them do return a value or result set).
cheers,
raf
^ permalink raw reply [nested|flat] 20+ messages in thread
* Re: Need help with clarification on stored procedure support in PostGreSQL database
@ 2021-03-08 23:31 Tom Lane <tgl@sss.pgh.pa.us>
parent: raf <raf@raf.org>
0 siblings, 1 reply; 20+ messages in thread
From: Tom Lane @ 2021-03-08 23:31 UTC (permalink / raw)
To: raf <raf@raf.org>; +Cc: Adrian Klaver <adrian.klaver@aklaver.com>; Bysani, Ram <rbysani@informatica.com>; pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
raf <raf@raf.org> writes:
> Is there any important different between a stored procedure and
> a stored function that returns void? I've been using functions
> for everything but calling them procedures in my head (even though
> most of them do return a value or result set).
A procedure can commit or rollback a transaction (and then start
a new one).
regards, tom lane
^ permalink raw reply [nested|flat] 20+ messages in thread
* Re: Need help with clarification on stored procedure support in PostGreSQL database
@ 2021-03-09 00:53 raf <raf@raf.org>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 20+ messages in thread
From: raf @ 2021-03-09 00:53 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Adrian Klaver <adrian.klaver@aklaver.com>; Bysani, Ram <rbysani@informatica.com>; pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
On Mon, Mar 08, 2021 at 06:31:56PM -0500, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> raf <raf@raf.org> writes:
> > Is there any important different between a stored procedure and
> > a stored function that returns void? I've been using functions
> > for everything but calling them procedures in my head (even though
> > most of them do return a value or result set).
>
> A procedure can commit or rollback a transaction (and then start
> a new one).
>
> regards, tom lane
thanks.
cheers,
raf
^ permalink raw reply [nested|flat] 20+ messages in thread
* Re: Need help with clarification on stored procedure support in PostGreSQL database
@ 2021-03-09 04:31 Guyren Howe <guyren@gmail.com>
parent: raf <raf@raf.org>
0 siblings, 2 replies; 20+ messages in thread
From: Guyren Howe @ 2021-03-09 04:31 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; raf <raf@raf.org>; +Cc: Adrian Klaver <adrian.klaver@aklaver.com>; Bysani, Ram <rbysani@informatica.com>; pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
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?
On Mar 8, 2021, 16:53 -0800, raf <raf@raf.org>, wrote:
> On Mon, Mar 08, 2021 at 06:31:56PM -0500, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>
> > raf <raf@raf.org> writes:
> > > Is there any important different between a stored procedure and
> > > a stored function that returns void? I've been using functions
> > > for everything but calling them procedures in my head (even though
> > > most of them do return a value or result set).
> >
> > A procedure can commit or rollback a transaction (and then start
> > a new one).
> >
> > regards, tom lane
>
> thanks.
>
> cheers,
> raf
>
>
>
^ permalink raw reply [nested|flat] 20+ messages in thread
* Re: Need help with clarification on stored procedure support in PostGreSQL database
@ 2021-03-09 04:39 Brent Wood <Brent.Wood@niwa.co.nz>
parent: Guyren Howe <guyren@gmail.com>
1 sibling, 0 replies; 20+ messages in thread
From: Brent Wood @ 2021-03-09 04:39 UTC (permalink / raw)
To: Guyren Howe <guyren@gmail.com>; +Cc: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
They are discussed here,
https://kb.objectrocket.com/postgresql/function-vs-stored-procedure-602
(from this page):
The main difference between function and stored procedure is that user-defined functions do not execute transactions. This means, inside a given function you cannot open a new transaction, neither can you commit or rollback the current transaction. It is important to note that stored procedures are just functions that can support transactions and were introduced in Postgresql 11. PostgreSQL functions can be created in a variety of languages including SQL, PL/pgSQL, C, Python.
Perhaps add some detail from here to the official docs?
Brent Wood
Principal Technician, Fisheries
NIWA
DDI: +64 (4) 3860529
________________________________
From: Guyren Howe <guyren@gmail.com>
Sent: Tuesday, March 9, 2021 17:31
To: Tom Lane <tgl@sss.pgh.pa.us>; raf <raf@raf.org>
Cc: Adrian Klaver <adrian.klaver@aklaver.com>; Bysani, Ram <rbysani@informatica.com>; pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: Need help with clarification on stored procedure support in PostGreSQL database
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?
On Mar 8, 2021, 16:53 -0800, raf <raf@raf.org>, wrote:
On Mon, Mar 08, 2021 at 06:31:56PM -0500, Tom Lane <tgl@sss.pgh.pa.us> wrote:
raf <raf@raf.org> writes:
Is there any important different between a stored procedure and
a stored function that returns void? I've been using functions
for everything but calling them procedures in my head (even though
most of them do return a value or result set).
A procedure can commit or rollback a transaction (and then start
a new one).
regards, tom lane
thanks.
cheers,
raf
[https://www.niwa.co.nz/static/niwa-2018-horizontal-180.png][https://niwa.co.nz/sites/niwa.co.nz/files/ETNZ_Official-supplier-logo-75h.png]<https://www.niwa.co.nz;
Brent Wood
Principal Technician - GIS and Spatial Data Management
Programme Leader - Environmental Information Delivery
+64-4-386-0529
National Institute of Water & Atmospheric Research Ltd (NIWA)
301 Evans Bay Parade Hataitai Wellington New Zealand
Connect with NIWA: niwa.co.nz<https://www.niwa.co.nz; Facebook<https://www.facebook.com/nzniwa; LinkedIn<https://www.linkedin.com/company/niwa; Twitter<https://twitter.com/niwa_nz; Instagram<https://www.instagram.com/niwa_science;
To ensure compliance with legal requirements and to maintain cyber security standards, NIWA's IT systems are subject to ongoing monitoring, activity logging and auditing. This monitoring and auditing service may be provided by third parties. Such third parties can access information transmitted to, processed by and stored on NIWA's IT systems
^ permalink raw reply [nested|flat] 20+ messages in thread
* Re: Need help with clarification on stored procedure support in PostGreSQL database
@ 2021-03-09 04:41 Tom Lane <tgl@sss.pgh.pa.us>
parent: Guyren Howe <guyren@gmail.com>
1 sibling, 2 replies; 20+ messages in thread
From: Tom Lane @ 2021-03-09 04:41 UTC (permalink / raw)
To: Guyren Howe <guyren@gmail.com>; +Cc: raf <raf@raf.org>; Adrian Klaver <adrian.klaver@aklaver.com>; Bysani, Ram <rbysani@informatica.com>; pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
Guyren Howe <guyren@gmail.com> 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
regards, tom lane
^ permalink raw reply [nested|flat] 20+ messages in thread
* Re: Need help with clarification on stored procedure support in PostGreSQL database
@ 2021-03-09 04:47 Guyren Howe <guyren@gmail.com>
parent: Tom Lane <tgl@sss.pgh.pa.us>
1 sibling, 0 replies; 20+ messages in thread
From: Guyren Howe @ 2021-03-09 04:47 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: raf <raf@raf.org>; Adrian Klaver <adrian.klaver@aklaver.com>; Bysani, Ram <rbysani@informatica.com>; pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
I think that’s burying the lede a bit. Still, unless the “Extending SQL Section” acquired an Overview section, I’m not sure where else you’d put it.
On Mar 8, 2021, 20:41 -0800, Tom Lane <tgl@sss.pgh.pa.us>, wrote:
> Guyren Howe <guyren@gmail.com> 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
>
> regards, tom lane
^ permalink raw reply [nested|flat] 20+ messages in thread
* Re: Need help with clarification on stored procedure support in PostGreSQL database
@ 2021-03-09 04:47 David G. Johnston <david.g.johnston@gmail.com>
parent: Tom Lane <tgl@sss.pgh.pa.us>
1 sibling, 1 reply; 20+ messages in thread
From: David G. Johnston @ 2021-03-09 04:47 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Guyren Howe <guyren@gmail.com>; raf <raf@raf.org>; Adrian Klaver <adrian.klaver@aklaver.com>; Bysani, Ram <rbysani@informatica.com>; pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
On Mon, Mar 8, 2021 at 9:41 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Guyren Howe <guyren@gmail.com> 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".
David J.
^ permalink raw reply [nested|flat] 20+ messages in thread
* Re: Need help with clarification on stored procedure support in PostGreSQL database
@ 2021-03-09 20:57 Tom Lane <tgl@sss.pgh.pa.us>
parent: David G. Johnston <david.g.johnston@gmail.com>
0 siblings, 1 reply; 20+ messages in thread
From: Tom Lane @ 2021-03-09 20:57 UTC (permalink / raw)
To: David G. Johnston <david.g.johnston@gmail.com>; +Cc: Peter Eisentraut <peter.eisentraut@enterprisedb.com>; Guyren Howe <guyren@gmail.com>; raf <raf@raf.org>; Adrian Klaver <adrian.klaver@aklaver.com>; Bysani, Ram <rbysani@informatica.com>; pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
"David G. Johnston" <david.g.johnston@gmail.com> writes:
> On Mon, Mar 8, 2021 at 9:41 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> Guyren Howe <guyren@gmail.com> 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
Attachments:
improve-procedure-docs.patch (text/x-diff, 3.9K) download
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 <command>DO</command> block can call a procedure
using <command>CALL</command>. Output parameters are handled
differently from the way that <command>CALL</command> works in plain
- SQL. Each <literal>INOUT</literal> parameter of the procedure must
+ SQL. Each <literal>OUT</literal> or <literal>INOUT</literal>
+ parameter of the procedure must
correspond to a variable in the <command>CALL</command> statement, and
whatever the procedure returns is assigned back to that variable after
it returns. For example:
diff --git a/doc/src/sgml/ref/create_function.sgml b/doc/src/sgml/ref/create_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 <literal>USAGE</literal>
privilege on the argument types and the return type.
</para>
+
+ <para>
+ Refer to <xref linkend="xfunc"/> for further information on writing
+ functions.
+ </para>
</refsect1>
<refsect1>
@@ -578,12 +583,6 @@ CREATE [ OR REPLACE ] FUNCTION
</varlistentry>
</variablelist>
-
- <para>
- Refer to <xref linkend="xfunc"/> for further information on writing
- functions.
- </para>
-
</refsect1>
<refsect1 id="sql-createfunction-overloading">
diff --git a/doc/src/sgml/ref/create_procedure.sgml b/doc/src/sgml/ref/create_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 <literal>USAGE</literal>
privilege on the argument types.
</para>
+
+ <para>
+ Refer to <xref linkend="xproc"/> for further information on writing
+ procedures.
+ </para>
</refsect1>
<refsect1>
@@ -328,6 +333,10 @@ $$;
CALL insert_data(1, 2);
</programlisting>
+
+ <para>
+ For more information and examples, see <xref linkend="xproc"/>.
+ </para>
</refsect1>
<refsect1 id="sql-createprocedure-compat">
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 @@
</indexterm>
<para>
- A procedure is a database object similar to a function. The difference is
+ A procedure is a database object similar to a function. One difference 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 <link linkend="sql-call"><command>CALL</command></link> command. If the <command>CALL</command> 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.
</para>
<para>
- 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 <link linkend="sql-createprocedure"><command>CREATE PROCEDURE</command></link> command is used instead, there is
no return type, and some other features such as strictness don't apply.
</para>
^ permalink raw reply [nested|flat] 20+ messages in thread
* Re: Need help with clarification on stored procedure support in PostGreSQL database
@ 2021-03-09 22:16 David G. Johnston <david.g.johnston@gmail.com>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 20+ messages in thread
From: David G. Johnston @ 2021-03-09 22:16 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Peter Eisentraut <peter.eisentraut@enterprisedb.com>; Guyren Howe <guyren@gmail.com>; raf <raf@raf.org>; Adrian Klaver <adrian.klaver@aklaver.com>; Bysani, Ram <rbysani@informatica.com>; pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
On Tue, Mar 9, 2021 at 1:57 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
> "David G. Johnston" <david.g.johnston@gmail.com> writes:
> > On Mon, Mar 8, 2021 at 9:41 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
> >> Guyren Howe <guyren@gmail.com> 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 ...
>
>
Thanks. Some observations.
The omission of the "OUT" parameter mode seems intentional since at present
our procedures do not support OUT mode parameters.
Instead of "The difference" or "One difference" I would suggest: "However,
a procedure does not return a value, so there is no return type
declaration; though a procedure can declare INOUT (but not plain OUT)
parameters."
Relocating the links to the description instead of usage is good. The
additional procedure link after the examples seems redundant, particularly
as the linked to location doesn't actually have more examples. The
"...further information on writing" doesn't really match up with reality
either. It is more "...further information on incorporating
functions/procedures into applications."
David J.
^ permalink raw reply [nested|flat] 20+ messages in thread
* Re: Need help with clarification on stored procedure support in PostGreSQL database
@ 2021-03-09 22:21 Tom Lane <tgl@sss.pgh.pa.us>
parent: David G. Johnston <david.g.johnston@gmail.com>
0 siblings, 1 reply; 20+ messages in thread
From: Tom Lane @ 2021-03-09 22:21 UTC (permalink / raw)
To: David G. Johnston <david.g.johnston@gmail.com>; +Cc: Peter Eisentraut <peter.eisentraut@enterprisedb.com>; Guyren Howe <guyren@gmail.com>; raf <raf@raf.org>; Adrian Klaver <adrian.klaver@aklaver.com>; Bysani, Ram <rbysani@informatica.com>; pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
"David G. Johnston" <david.g.johnston@gmail.com> writes:
> The omission of the "OUT" parameter mode seems intentional since at present
> our procedures do not support OUT mode parameters.
Um, I just created one. I think this *used* to be true, and this bit of
the docs didn't get fixed. If I back-patch this, I'll have to research
when it changed.
> Instead of "The difference" or "One difference" I would suggest: "However,
> a procedure does not return a value, so there is no return type
> declaration; though a procedure can declare INOUT (but not plain OUT)
> parameters."
Not sure if that's an improvement.
> Relocating the links to the description instead of usage is good. The
> additional procedure link after the examples seems redundant, particularly
> as the linked to location doesn't actually have more examples.
I was modeling that on the existing pattern in create_function.sgml,
which has similar verbiage in the EXAMPLES section. But I suppose
we could drop that if we have a link in the description section.
regards, tom lane
^ permalink raw reply [nested|flat] 20+ messages in thread
* Re: Need help with clarification on stored procedure support in PostGreSQL database
@ 2021-03-09 23:16 David G. Johnston <david.g.johnston@gmail.com>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 20+ messages in thread
From: David G. Johnston @ 2021-03-09 23:16 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Peter Eisentraut <peter.eisentraut@enterprisedb.com>; Guyren Howe <guyren@gmail.com>; raf <raf@raf.org>; Adrian Klaver <adrian.klaver@aklaver.com>; Bysani, Ram <rbysani@informatica.com>; pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
On Tue, Mar 9, 2021 at 3:21 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
> "David G. Johnston" <david.g.johnston@gmail.com> writes:
> > The omission of the "OUT" parameter mode seems intentional since at
> present
> > our procedures do not support OUT mode parameters.
>
> Um, I just created one. I think this *used* to be true, and this bit of
> the docs didn't get fixed. If I back-patch this, I'll have to research
> when it changed.
>
Five months ago it seems.
https://github.com/postgres/postgres/commit/2453ea142233ae57af452019c3b9a443dad1cdd0
The patch and email thread for that commit make me pause, though I cannot
put into words why.
>
> > Instead of "The difference" or "One difference" I would suggest:
> "However,
> > a procedure does not return a value, so there is no return type
> > declaration; though a procedure can declare INOUT (but not plain OUT)
> > parameters."
>
> Not sure if that's an improvement.
>
The "however" part is probably a wash; I just dislike seeing a count
started and not having an ending and thus being left in a state of "what
didn't they include that's important".
The part about commenting about OUT/INOUT parameters still working even
though there is no return provide complete coverage of the
differences/similarities between functions and procedures with respect to
passing back data to the caller.
>
> > Relocating the links to the description instead of usage is good. The
> > additional procedure link after the examples seems redundant,
> particularly
> > as the linked to location doesn't actually have more examples.
>
> I was modeling that on the existing pattern in create_function.sgml,
> which has similar verbiage in the EXAMPLES section. But I suppose
> we could drop that if we have a link in the description section.
>
>
Yeah, it was an existing deficiency, but being a bit more invasive seems
warranted, and as you say it is be located partly because it is much higher
level content being pointed to (hence description, not usage/examples).
David J.
^ permalink raw reply [nested|flat] 20+ messages in thread
* Re: Need help with clarification on stored procedure support in PostGreSQL database
@ 2021-03-09 23:50 Tom Lane <tgl@sss.pgh.pa.us>
parent: David G. Johnston <david.g.johnston@gmail.com>
0 siblings, 1 reply; 20+ messages in thread
From: Tom Lane @ 2021-03-09 23:50 UTC (permalink / raw)
To: David G. Johnston <david.g.johnston@gmail.com>; +Cc: Peter Eisentraut <peter.eisentraut@enterprisedb.com>; Guyren Howe <guyren@gmail.com>; raf <raf@raf.org>; Adrian Klaver <adrian.klaver@aklaver.com>; Bysani, Ram <rbysani@informatica.com>; pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
"David G. Johnston" <david.g.johnston@gmail.com> writes:
> On Tue, Mar 9, 2021 at 3:21 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> "David G. Johnston" <david.g.johnston@gmail.com> writes:
>>> Instead of "The difference" or "One difference" I would suggest:
>>> "However, a procedure does not return a value, so there is no return type
>>> declaration; though a procedure can declare INOUT (but not plain OUT)
>>> parameters."
>> Not sure if that's an improvement.
> The "however" part is probably a wash; I just dislike seeing a count
> started and not having an ending and thus being left in a state of "what
> didn't they include that's important".
The rest of the paragraph is what's important enough to include here.
I very strongly dislike the existing "The difference ..." wording,
because it implies that that's the only difference, which is immediately
belied by the rest. "However" isn't a lot better. Would it be better
to turn the para into a bulleted list, which we could introduce with
"The key differences are:" ?
regards, tom lane
^ permalink raw reply [nested|flat] 20+ messages in thread
* Re: Need help with clarification on stored procedure support in PostGreSQL database
@ 2021-03-09 23:54 David G. Johnston <david.g.johnston@gmail.com>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 20+ messages in thread
From: David G. Johnston @ 2021-03-09 23:54 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Peter Eisentraut <peter.eisentraut@enterprisedb.com>; Guyren Howe <guyren@gmail.com>; raf <raf@raf.org>; Adrian Klaver <adrian.klaver@aklaver.com>; Bysani, Ram <rbysani@informatica.com>; pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
On Tue, Mar 9, 2021 at 4:50 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
> I very strongly dislike the existing "The difference ..." wording,
> because it implies that that's the only difference, which is immediately
> belied by the rest.
Agreed!
> 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.
David J.
^ permalink raw reply [nested|flat] 20+ messages in thread
* Re: Need help with clarification on stored procedure support in PostGreSQL database
@ 2021-03-10 00:18 Tom Lane <tgl@sss.pgh.pa.us>
parent: David G. Johnston <david.g.johnston@gmail.com>
0 siblings, 1 reply; 20+ messages in thread
From: Tom Lane @ 2021-03-10 00:18 UTC (permalink / raw)
To: David G. Johnston <david.g.johnston@gmail.com>; +Cc: Peter Eisentraut <peter.eisentraut@enterprisedb.com>; Guyren Howe <guyren@gmail.com>; raf <raf@raf.org>; Adrian Klaver <adrian.klaver@aklaver.com>; Bysani, Ram <rbysani@informatica.com>; pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
"David G. Johnston" <david.g.johnston@gmail.com> writes:
> On Tue, Mar 9, 2021 at 4:50 PM Tom Lane <tgl@sss.pgh.pa.us> 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
Attachments:
improve-procedure-docs-2.patch (text/x-diff, 5.3K) download
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 <command>DO</command> block can call a procedure
using <command>CALL</command>. Output parameters are handled
differently from the way that <command>CALL</command> works in plain
- SQL. Each <literal>INOUT</literal> parameter of the procedure must
+ SQL. Each <literal>OUT</literal> or <literal>INOUT</literal>
+ parameter of the procedure must
correspond to a variable in the <command>CALL</command> statement, and
whatever the procedure returns is assigned back to that variable after
it returns. For example:
diff --git a/doc/src/sgml/ref/create_function.sgml b/doc/src/sgml/ref/create_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 <literal>USAGE</literal>
privilege on the argument types and the return type.
</para>
+
+ <para>
+ Refer to <xref linkend="xfunc"/> for further information on writing
+ functions.
+ </para>
</refsect1>
<refsect1>
@@ -578,12 +583,6 @@ CREATE [ OR REPLACE ] FUNCTION
</varlistentry>
</variablelist>
-
- <para>
- Refer to <xref linkend="xfunc"/> for further information on writing
- functions.
- </para>
-
</refsect1>
<refsect1 id="sql-createfunction-overloading">
@@ -661,8 +660,7 @@ CREATE FUNCTION foo(int, int default 42) ...
<title>Examples</title>
<para>
- Here are some trivial examples to help you get started. For more
- information and examples, see <xref linkend="xfunc"/>.
+ Add two integers using a SQL function:
<programlisting>
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/create_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 <literal>USAGE</literal>
privilege on the argument types.
</para>
+
+ <para>
+ Refer to <xref linkend="xproc"/> for further information on writing
+ procedures.
+ </para>
</refsect1>
<refsect1>
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 @@
</indexterm>
<para>
- A procedure is a database object similar to a function. The difference 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 <link linkend="sql-call"><command>CALL</command></link> command. If the <command>CALL</command> 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:
+
+ <itemizedlist>
+ <listitem>
+ <para>
+ Procedures are defined with
+ the <link linkend="sql-createprocedure"><command>CREATE
+ PROCEDURE</command></link> command, not <command>CREATE
+ FUNCTION</command>.
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ Procedures do not return a function value; hence <command>CREATE
+ PROCEDURE</command> lacks a <literal>RETURNS</literal> clause.
+ However, procedures can instead return data to their callers via
+ output parameters.
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ While a function is called as part of a query or DML command, a
+ procedure is called in isolation using
+ the <link linkend="sql-call"><command>CALL</command></link> command.
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ If the invoking <command>CALL</command> 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.
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ 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.
+ </para>
+ </listitem>
+ </itemizedlist>
</para>
<para>
- The explanations on how to define user-defined functions in the rest of
- this chapter apply to procedures as well, except that
- the <link linkend="sql-createprocedure"><command>CREATE PROCEDURE</command></link> command is used instead, there is
- no return type, and some other features such as strictness don't apply.
+ The explanations in the following sections about how to define
+ user-defined functions apply to procedures as well, except for the
+ points made above.
</para>
<para>
^ permalink raw reply [nested|flat] 20+ messages in thread
* Re: Need help with clarification on stored procedure support in PostGreSQL database
@ 2021-03-10 15:53 David G. Johnston <david.g.johnston@gmail.com>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 20+ messages in thread
From: David G. Johnston @ 2021-03-10 15:53 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Peter Eisentraut <peter.eisentraut@enterprisedb.com>; Guyren Howe <guyren@gmail.com>; raf <raf@raf.org>; Adrian Klaver <adrian.klaver@aklaver.com>; Bysani, Ram <rbysani@informatica.com>; pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
On Tue, Mar 9, 2021 at 5:18 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
> "David G. Johnston" <david.g.johnston@gmail.com> writes:
> > On Tue, Mar 9, 2021 at 4:50 PM Tom Lane <tgl@sss.pgh.pa.us> 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.
>
>
Thank you. That reads much better, aside from maybe a couple of missing
commas.
- Certain function attributes such as strictness don't apply to
+ Certain function attributes, such as strictness, don't apply to
David J.
^ permalink raw reply [nested|flat] 20+ messages in thread
* Re: Need help with clarification on stored procedure support in PostGreSQL database
@ 2021-03-10 16:35 Tom Lane <tgl@sss.pgh.pa.us>
parent: David G. Johnston <david.g.johnston@gmail.com>
0 siblings, 0 replies; 20+ messages in thread
From: Tom Lane @ 2021-03-10 16:35 UTC (permalink / raw)
To: David G. Johnston <david.g.johnston@gmail.com>; +Cc: Peter Eisentraut <peter.eisentraut@enterprisedb.com>; Guyren Howe <guyren@gmail.com>; raf <raf@raf.org>; Adrian Klaver <adrian.klaver@aklaver.com>; Bysani, Ram <rbysani@informatica.com>; pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
"David G. Johnston" <david.g.johnston@gmail.com> writes:
> On Tue, Mar 9, 2021 at 5:18 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> v2 attached.
> Thank you. That reads much better, aside from maybe a couple of missing
> commas.
> - Certain function attributes such as strictness don't apply to
> + Certain function attributes, such as strictness, don't apply to
I see your point, but that ends up with way too many commas in the
sentence. After puzzling a bit, I broke it into two sentences.
Done like that, thanks for the discussion!
regards, tom lane
^ permalink raw reply [nested|flat] 20+ messages in thread
end of thread, other threads:[~2021-03-10 16:35 UTC | newest]
Thread overview: 20+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-03-07 18:48 Need help with clarification on stored procedure support in PostGreSQL database Bysani, Ram <rbysani@informatica.com>
2021-03-07 18:52 ` David G. Johnston <david.g.johnston@gmail.com>
2021-03-07 19:01 ` Adrian Klaver <adrian.klaver@aklaver.com>
2021-03-08 22:22 ` raf <raf@raf.org>
2021-03-08 23:31 ` Tom Lane <tgl@sss.pgh.pa.us>
2021-03-09 00:53 ` raf <raf@raf.org>
2021-03-09 04:31 ` Guyren Howe <guyren@gmail.com>
2021-03-09 04:39 ` Brent Wood <Brent.Wood@niwa.co.nz>
2021-03-09 04:41 ` Tom Lane <tgl@sss.pgh.pa.us>
2021-03-09 04:47 ` Guyren Howe <guyren@gmail.com>
2021-03-09 04:47 ` David G. Johnston <david.g.johnston@gmail.com>
2021-03-09 20:57 ` Tom Lane <tgl@sss.pgh.pa.us>
2021-03-09 22:16 ` David G. Johnston <david.g.johnston@gmail.com>
2021-03-09 22:21 ` Tom Lane <tgl@sss.pgh.pa.us>
2021-03-09 23:16 ` David G. Johnston <david.g.johnston@gmail.com>
2021-03-09 23:50 ` Tom Lane <tgl@sss.pgh.pa.us>
2021-03-09 23:54 ` David G. Johnston <david.g.johnston@gmail.com>
2021-03-10 00:18 ` Tom Lane <tgl@sss.pgh.pa.us>
2021-03-10 15:53 ` David G. Johnston <david.g.johnston@gmail.com>
2021-03-10 16:35 ` Tom Lane <tgl@sss.pgh.pa.us>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox