[HACKERS] SQL procedures
[HACKERS] SQL procedures
I've been working on SQL procedures. (Some might call them "stored procedures", but I'm not aware of any procedures that are not stored, so that's not a term that I'm using here.) Everything that follows is intended to align with the SQL standard, at least in spirit. This first patch does a bunch of preparation work. It adds the CREATE/ALTER/DROP PROCEDURE commands and the CALL statement to call a procedure. It also adds ROUTINE syntax which can refer to a function or procedure. I have extended that to include aggregates. And then there is a bunch of leg work, such as psql and pg_dump support. The documentation is a lot of copy-and-paste right now; that can be revisited sometime. The provided procedural languages (an ever more confusing term) each needed a small touch-up to handle pg_proc entries with prorettype == 0. Right now, there is no support for returning values from procedures via OUT parameters. That will need some definitional pondering; and see also below for a possible alternative. With this, you can write procedures that are somewhat compatible with DB2, MySQL, and to a lesser extent Oracle. Separately, I will send patches that implement (the beginnings of) two separate features on top of this: - Transaction control in procedure bodies - Returning multiple result sets (In various previous discussions on "real stored procedures" or something like that, most people seemed to have one of these two features in mind. I think that depends on what other SQL systems one has worked with previously.) -- Peter Eisentraut http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers
Re: [HACKERS] SQL procedures
От:
Simon Riggs <simon@2ndquadrant.com>
Дата:
On 31 October 2017 at 18:23, Peter Eisentraut wrote: > I've been working on SQL procedures. (Some might call them "stored > procedures", but I'm not aware of any procedures that are not stored, so > that's not a term that I'm using here.) I guess that the DO command might have a variant to allow you to execute a procedure that isn't stored? Not suggesting you implement that, just thinking about why/when the "stored" word would be appropriate. -- Simon Riggs http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers
Re: [HACKERS] SQL procedures
От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Peter Eisentraut writes: > I've been working on SQL procedures. No comment yet on the big picture here, but ... > The provided procedural languages (an ever more > confusing term) each needed a small touch-up to handle pg_proc entries > with prorettype == 0. Putting 0 in prorettype seems like a pretty bad idea. Why not use VOIDOID for the prorettype value? Or if there is some reason why "void" isn't the right pseudotype, maybe you should invent a new one, analogous to the "trigger" and "event_trigger" pseudotypes. regards, tom lane -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers
Re: [HACKERS] SQL procedures
От:
Pavel Stehule <pavel.stehule@gmail.com>
Дата:
2017-10-31 18:23 GMT+01:00 Peter Eisentraut <peter.eisentraut@2ndquadrant.com>:
I've been working on SQL procedures. (Some might call them "stored
procedures", but I'm not aware of any procedures that are not stored, so
that's not a term that I'm using here.)
Everything that follows is intended to align with the SQL standard, at
least in spirit.
This first patch does a bunch of preparation work. It adds the
CREATE/ALTER/DROP PROCEDURE commands and the CALL statement to call a
procedure. It also adds ROUTINE syntax which can refer to a function or
procedure. I have extended that to include aggregates. And then there
is a bunch of leg work, such as psql and pg_dump support. The
documentation is a lot of copy-and-paste right now; that can be
revisited sometime. The provided procedural languages (an ever more
confusing term) each needed a small touch-up to handle pg_proc entries
with prorettype == 0.
Right now, there is no support for returning values from procedures via
OUT parameters. That will need some definitional pondering; and see
also below for a possible alternative.
With this, you can write procedures that are somewhat compatible with
DB2, MySQL, and to a lesser extent Oracle.
Separately, I will send patches that implement (the beginnings of) two
separate features on top of this:
- Transaction control in procedure bodies
- Returning multiple result sets
(In various previous discussions on "real stored procedures" or
something like that, most people seemed to have one of these two
features in mind. I think that depends on what other SQL systems one
has worked with previously.)
great. I hope so I can help with testing
Regards
Pavel
--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
Re: [HACKERS] SQL procedures
От:
Pavel Stehule <pavel.stehule@gmail.com>
Дата:
2017-10-31 18:23 GMT+01:00 Peter Eisentraut <peter.eisentraut@2ndquadrant.com>:
I've been working on SQL procedures. (Some might call them "stored
procedures", but I'm not aware of any procedures that are not stored, so
that's not a term that I'm using here.)
Everything that follows is intended to align with the SQL standard, at
least in spirit.
This first patch does a bunch of preparation work. It adds the
CREATE/ALTER/DROP PROCEDURE commands and the CALL statement to call a
procedure. It also adds ROUTINE syntax which can refer to a function or
procedure. I have extended that to include aggregates. And then there
is a bunch of leg work, such as psql and pg_dump support. The
documentation is a lot of copy-and-paste right now; that can be
revisited sometime. The provided procedural languages (an ever more
confusing term) each needed a small touch-up to handle pg_proc entries
with prorettype == 0.
Right now, there is no support for returning values from procedures via
OUT parameters. That will need some definitional pondering; and see
also below for a possible alternative.
With this, you can write procedures that are somewhat compatible with
DB2, MySQL, and to a lesser extent Oracle.
Separately, I will send patches that implement (the beginnings of) two
separate features on top of this:
- Transaction control in procedure bodies
- Returning multiple result sets
(In various previous discussions on "real stored procedures" or
something like that, most people seemed to have one of these two
features in mind. I think that depends on what other SQL systems one
has worked with previously.)
Not sure if disabling RETURN is good idea. I can imagine so optional returning something like int status can be good idea. Cheaper than raising a exception.
Regards
Pavel
--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
Re: [HACKERS] SQL procedures
От:
Simon Riggs <simon@2ndquadrant.com>
Дата:
On 31 October 2017 at 17:23, Peter Eisentraut wrote: > I've been working on SQL procedures. (Some might call them "stored > procedures", but I'm not aware of any procedures that are not stored, so > that's not a term that I'm using here.) Looks good > Everything that follows is intended to align with the SQL standard, at > least in spirit. +1 > This first patch does a bunch of preparation work. It adds the > CREATE/ALTER/DROP PROCEDURE commands and the CALL statement to call a > procedure. I guess it would be really useful to have a cut-down language to use as an example, but its probably easier to just wait for PLpgSQL. You mention PARALLEL SAFE is not used for procedures. Isn't it an architectural restriction that procedures would not be able to execute in parallel? (At least this year) > It also adds ROUTINE syntax which can refer to a function or > procedure. I think we need an explanatory section of the docs, but there doesn't seem to be one for Functions, so there is no place to add some text that says the above. I found it confusing that ALTER and DROP ROUTINE exists but not CREATE ROUTINE. At very least we should say somewhere "there is no CREATE ROUTINE", so its absence is clearly intentional. I did wonder whether we should have it as well, but its just one less thing to review, so good. Was surprised that pg_dump didn't use DROP ROUTINE, when appropriate. > I have extended that to include aggregates. And then there > is a bunch of leg work, such as psql and pg_dump support. The > documentation is a lot of copy-and-paste right now; that can be > revisited sometime. The provided procedural languages (an ever more > confusing term) each needed a small touch-up to handle pg_proc entries > with prorettype == 0. > > Right now, there is no support for returning values from procedures via > OUT parameters. That will need some definitional pondering; and see > also below for a possible alternative. > > With this, you can write procedures that are somewhat compatible with > DB2, MySQL, and to a lesser extent Oracle. > > Separately, I will send patches that implement (the beginnings of) two > separate features on top of this: > > - Transaction control in procedure bodies > > - Returning multiple result sets Both of those would be good, though my suggested priority would be transaction control first and then multiple result sets, if we cannot have both this release. > (In various previous discussions on "real stored procedures" or > something like that, most people seemed to have one of these two > features in mind. I think that depends on what other SQL systems one > has worked with previously.) Almost all of the meat happens in later patches, so no other review comments. That seems seems strange in a patch of this size, but its true. Procedures are just a new type of object with very little interaction with replication, persistence or optimization. -- Simon Riggs http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers
Re: [HACKERS] SQL procedures
От:
Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
Дата:
On 10/31/17 14:23, Tom Lane wrote: > Putting 0 in prorettype seems like a pretty bad idea. It seemed like the natural thing to do, since we use a zero OID to indicate "nothing" in many other places. > Why not use VOIDOID for the prorettype value? We need a way to distinguish functions that are callable by SELECT and procedures that are callable by CALL. > Or if there is some reason why "void" isn't the > right pseudotype, maybe you should invent a new one, analogous to the > "trigger" and "event_trigger" pseudotypes. I guess that would be doable, but I think it would make things more complicated without any gain that I can see. In the case of the pseudotypes you mention, those are the actual types mentioned in the CREATE FUNCTION command. If we invented a new pseudotype, that would run the risk of existing code creating nonsensical reverse compilations like CREATE FUNCTION RETURNS PROCEDURE. Catalog queries using prorettype == 0 would behave sensibly by default. For example, an inner or outer join against pg_type would automatically make sense. -- Peter Eisentraut http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers
Re: [HACKERS] SQL procedures
От:
Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
Дата:
On 10/31/17 16:50, Pavel Stehule wrote: > Not sure if disabling RETURN is good idea. I can imagine so optional > returning something like int status can be good idea. Cheaper than > raising a exception. We could allow a RETURN without argument in PL/pgSQL, if you just want to exit early. That syntax is currently not available, but it should not be hard to add. I don't understand the point about wanting to return an int. How would you pass that around, since there is no declared return type? -- Peter Eisentraut http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers
Re: [HACKERS] SQL procedures
От:
Merlin Moncure <mmoncure@gmail.com>
Дата:
On Tue, Oct 31, 2017 at 12:23 PM, Peter Eisentraut wrote: > - Transaction control in procedure bodies This feature is really key, since it enables via SQL lots of things that are not possible without external coding, including: *) very long running processes in a single routine *) transaction isolation control inside the procedure (currently client app has to declare this) *) certain error handling cases that require client side support *) simple in-database threading *) simple construction of daemon scripts (yeah, you can use bgworker for this, but pure sql daemon with a cron heartbeat hook is hard to beat for simplicity) I do wonder how transaction control could be added later. The last time I (lightly) looked at this, I was starting to think that working transaction control into the SPI interface was the wrong approach; pl/pgsql would have to adopt a very different set of behaviors if it was called in a function or a proc. If you restricted language choice to purely SQL, you could work around this problem; SPI languages would be totally abstracted from those sets of considerations and you could always call an arbitrary language function if you needed to. SQL has no flow control but I'm not too concerned about that. merlin -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers
Re: [HACKERS] SQL procedures
От:
Pavel Stehule <pavel.stehule@gmail.com>
Дата:
2017-11-08 15:23 GMT+01:00 Peter Eisentraut <peter.eisentraut@2ndquadrant.com>:
On 10/31/17 16:50, Pavel Stehule wrote:
> Not sure if disabling RETURN is good idea. I can imagine so optional
> returning something like int status can be good idea. Cheaper than
> raising a exception.
We could allow a RETURN without argument in PL/pgSQL, if you just want
to exit early. That syntax is currently not available, but it should
not be hard to add.
I don't understand the point about wanting to return an int. How would
you pass that around, since there is no declared return type?
We can create auto session variable STATUS. This variable can be 0 if procedure was returned without explicit RETURN value. Or it can hold different value specified by RETURN expr.
This value can be read by GET DIAGNOSTICS xxx = STATUS
or some similar.
--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Re: [HACKERS] SQL procedures
От:
Pavel Stehule <pavel.stehule@gmail.com>
Дата:
2017-11-08 15:31 GMT+01:00 Pavel Stehule <pavel.stehule@gmail.com>:
2017-11-08 15:23 GMT+01:00 Peter Eisentraut <peter.eisentraut@2ndquadrant.com>: On 10/31/17 16:50, Pavel Stehule wrote:
> Not sure if disabling RETURN is good idea. I can imagine so optional
> returning something like int status can be good idea. Cheaper than
> raising a exception.
We could allow a RETURN without argument in PL/pgSQL, if you just want
to exit early. That syntax is currently not available, but it should
not be hard to add.
I don't understand the point about wanting to return an int. How would
you pass that around, since there is no declared return type?We can create auto session variable STATUS. This variable can be 0 if procedure was returned without explicit RETURN value. Or it can hold different value specified by RETURN expr.This value can be read by GET DIAGNOSTICS xxx = STATUSor some similar.
The motivation is allow some mechanism cheaper than our exceptions.
Regards
Pavel
--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Re: [HACKERS] SQL procedures
От:
Konstantin Knizhnik <k.knizhnik@postgrespro.ru>
Дата:
On 08.11.2017 17:23, Merlin Moncure wrote: > On Tue, Oct 31, 2017 at 12:23 PM, Peter Eisentraut > wrote: >> - Transaction control in procedure bodies > This feature is really key, since it enables via SQL lots of things > that are not possible without external coding, including: > *) very long running processes in a single routine > *) transaction isolation control inside the procedure (currently > client app has to declare this) > *) certain error handling cases that require client side support > *) simple in-database threading > *) simple construction of daemon scripts (yeah, you can use bgworker > for this, but pure sql daemon with a cron heartbeat hook is hard to > beat for simplicity) > > I do wonder how transaction control could be added later. > > The last time I (lightly) looked at this, I was starting to think that > working transaction control into the SPI interface was the wrong > approach; pl/pgsql would have to adopt a very different set of > behaviors if it was called in a function or a proc. If you restricted > language choice to purely SQL, you could work around this problem; SPI > languages would be totally abstracted from those sets of > considerations and you could always call an arbitrary language > function if you needed to. SQL has no flow control but I'm not too > concerned about that. > > merlin > > I am also very interested in answer on this question: how you are going to implement transaction control inside procedure? Right now in PostgresPRO EE supports autonomous transactions. Them are supported both for SQL and plpgsql/plpython APIs. Them are implemented by saving/restoring transaction context, so unlike most of other ATX implementations, in pgpro autonomous transaction is executed by the same backend. But it is not so easy to do: in Postgres almost any module have its own static variables which keeps transaction specific data. So we have to provide a dozen of suspend/resume functions: SuspendSnapshot(), SuspendPredicate(), SuspendStorage(), SuspendInvalidationInfo(), SuspendPgXact(), PgStatSuspend(), TriggerSuspend(), SuspendSPI()... and properly handle local cache invalidation. Patch consists of more than 5 thousand lines. So my question is whether you are going to implement something similar or use completely different approach? In first case it will be good to somehow unite our efforts... For example we can publish our ATX patch for Postgres 10. We have not done it yet, because there seems to be no chances to push this patch to community. -- Konstantin Knizhnik Postgres Professional: http://www.postgrespro.com The Russian Postgres Company -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers
Re: [HACKERS] SQL procedures
От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Peter Eisentraut writes: > On 10/31/17 14:23, Tom Lane wrote: >> Why not use VOIDOID for the prorettype value? > We need a way to distinguish functions that are callable by SELECT and > procedures that are callable by CALL. Do procedures of this ilk belong in pg_proc at all? It seems like a large fraction of the attributes tracked in pg_proc are senseless for this purpose. A new catalog might be a better approach. In any case, I buy none of your arguments that 0 is a better choice than a new pseudotype. regards, tom lane -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers
Re: [HACKERS] SQL procedures
От:
Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
Дата:
On 11/6/17 16:27, Simon Riggs wrote: > You mention PARALLEL SAFE is not used for procedures. Isn't it an > architectural restriction that procedures would not be able to execute > in parallel? (At least this year) I'm not sure what you are referring to here. I don't think the functionality I'm proposing does anything in parallel or has any interaction with it. > I think we need an explanatory section of the docs, but there doesn't > seem to be one for Functions, so there is no place to add some text > that says the above. > > I found it confusing that ALTER and DROP ROUTINE exists but not CREATE > ROUTINE. At very least we should say somewhere "there is no CREATE > ROUTINE", so its absence is clearly intentional. I did wonder whether > we should have it as well, but its just one less thing to review, so > good. I'll look for a place to add some documentation around this. > Was surprised that pg_dump didn't use DROP ROUTINE, when appropriate. It's not clear to me why that would be preferred. -- Peter Eisentraut http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers
Re: [HACKERS] SQL procedures
От:
Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
Дата:
On 11/8/17 09:33, Pavel Stehule wrote: > We can create auto session variable STATUS. This variable can be 0 > if procedure was returned without explicit RETURN value. Or it can > hold different value specified by RETURN expr. > > This value can be read by GET DIAGNOSTICS xxx = STATUS > > or some similar. > > The motivation is allow some mechanism cheaper than our exceptions. I suppose this could be a separately discussed feature. We'd also want to consider various things that PL/pgSQL pretends to be compatible with. One of the main motivations for procedures is to do more complex and expensive things including transaction control. So saving exception overhead is not really on the priority list there. -- Peter Eisentraut http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers
Re: [HACKERS] SQL procedures
От:
Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
Дата:
On 11/8/17 09:23, Merlin Moncure wrote: > I do wonder how transaction control could be added later. > > The last time I (lightly) looked at this, I was starting to think that > working transaction control into the SPI interface was the wrong > approach; pl/pgsql would have to adopt a very different set of > behaviors if it was called in a function or a proc. If you restricted > language choice to purely SQL, you could work around this problem; SPI > languages would be totally abstracted from those sets of > considerations and you could always call an arbitrary language > function if you needed to. SQL has no flow control but I'm not too > concerned about that. I have already submitted a separate patch that addresses these questions. -- Peter Eisentraut http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers
Re: [HACKERS] SQL procedures
От:
Merlin Moncure <mmoncure@gmail.com>
Дата:
On Wed, Nov 8, 2017 at 9:13 AM, Peter Eisentraut wrote: > I have already submitted a separate patch that addresses these questions. Maybe I'm obtuse, but I'm not seeing it? In very interested in the general approach to transaction management; if you've described it in the patch I'll read it there. Thanks for doing this. merlin -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers
Re: [HACKERS] SQL procedures
От:
Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
Дата:
On 11/8/17 11:11, Merlin Moncure wrote: > On Wed, Nov 8, 2017 at 9:13 AM, Peter Eisentraut > wrote: >> I have already submitted a separate patch that addresses these questions. > > Maybe I'm obtuse, but I'm not seeing it? In very interested in the > general approach to transaction management; if you've described it in > the patch I'll read it there. Thanks for doing this. https://www.postgresql.org/message-id/178d3380-0fae-2982-00d6-c43100bc8748@2ndquadrant.com -- Peter Eisentraut http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers
Re: [HACKERS] SQL procedures
От:
Merlin Moncure <mmoncure@gmail.com>
Дата:
On Wed, Nov 8, 2017 at 11:03 AM, Peter Eisentraut wrote: > On 11/8/17 11:11, Merlin Moncure wrote: >> On Wed, Nov 8, 2017 at 9:13 AM, Peter Eisentraut >> wrote: >>> I have already submitted a separate patch that addresses these questions. >> >> Maybe I'm obtuse, but I'm not seeing it? In very interested in the >> general approach to transaction management; if you've described it in >> the patch I'll read it there. Thanks for doing this. > > https://www.postgresql.org/message-id/178d3380-0fae-2982-00d6-c43100bc8748@2ndquadrant.com All right, thanks. So, *) Are you sure you want to go the SPI route? 'sql' language (non-spi) procedures might be simpler from implementation standpoint and do not need any language adjustments? *) Is it possible to jump into SPI without having a snapshot already set up. For example? If I wanted to set isolation level in a procedure, would I get impacted by this error? ERROR: SET TRANSACTION ISOLATION LEVEL must be called before any query merlin -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers
Re: [HACKERS] SQL procedures
От:
Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
Дата:
On 11/8/17 12:15, Merlin Moncure wrote: > On Wed, Nov 8, 2017 at 11:03 AM, Peter Eisentraut > wrote: >> On 11/8/17 11:11, Merlin Moncure wrote: >>> On Wed, Nov 8, 2017 at 9:13 AM, Peter Eisentraut >>> wrote: >>>> I have already submitted a separate patch that addresses these questions. >>> >>> Maybe I'm obtuse, but I'm not seeing it? In very interested in the >>> general approach to transaction management; if you've described it in >>> the patch I'll read it there. Thanks for doing this. >> >> https://www.postgresql.org/message-id/178d3380-0fae-2982-00d6-c43100bc8748@2ndquadrant.com > > All right, thanks. So, Could we have this discussion in that other thread? This thread is just about procedures at mostly a syntax level. -- Peter Eisentraut http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Re: [HACKERS] SQL procedures
Here is an updated patch. It's updated for the recent documentation format changes. I added some more documentation as suggested by reviewers. I also added more tests about how the various privilege commands (GRANT, GRANT on ALL, default privileges) would work with the new object type. I had not looked at that in much detail with the previous version of the patch, but it seems to work the way I would have wanted without any code changes, so it's all documentation additions and new tests. As part of this I have also developed additional tests for how the same privilege commands apply to aggregates, which didn't appear to be covered yet, and I was worried that I might have broken it, which it seems I did not. This is included in the big patch, but I have also included it here as a separate patch, as it could be committed independently as additional tests for existing functionality. It this point, this patch has no more open TODOs or need-to-think-about-this-later's that I'm aware of. -- Peter Eisentraut http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Re: [HACKERS] SQL procedures
От:
Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
Дата:
On 11/8/17 09:54, Tom Lane wrote: > Peter Eisentraut writes: >> On 10/31/17 14:23, Tom Lane wrote: >>> Why not use VOIDOID for the prorettype value? > >> We need a way to distinguish functions that are callable by SELECT and >> procedures that are callable by CALL. > > Do procedures of this ilk belong in pg_proc at all? It seems like a large > fraction of the attributes tracked in pg_proc are senseless for this > purpose. A new catalog might be a better approach. The common functionality between functions and procedures is like 98% [citation needed], so they definitely belong there, even more so than aggregates, for example. > In any case, I buy none of your arguments that 0 is a better choice than a > new pseudotype. Well, I haven't heard any reasons for doing it differently, so I can't judge the relative merits of either approach. Ultimately, it would be a minor detail as far as the code is concerned, I think. -- Peter Eisentraut http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Re: [HACKERS] SQL procedures
От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Peter Eisentraut writes: > On 11/8/17 09:54, Tom Lane wrote: >> Do procedures of this ilk belong in pg_proc at all? It seems like a large >> fraction of the attributes tracked in pg_proc are senseless for this >> purpose. A new catalog might be a better approach. > The common functionality between functions and procedures is like 98% > [citation needed], so they definitely belong there, even more so than > aggregates, for example. No, I don't think so. The core reason why not is that in SELECT foo(...) FROM ... foo() might be either a plain function or an aggregate, so it's important that functions and aggregates share the same namespace. *That* is why they are in the same catalog. On the other hand, since the above syntax is not usable to call a SQL procedure, putting SQL procedures into pg_proc just creates namespacing conflicts. Do we really want the existence of a function foo(int) to mean that you can't create a SQL procedure named foo and taking one int argument? regards, tom lane
Re: [HACKERS] SQL procedures
От:
Pavel Stehule <pavel.stehule@gmail.com>
Дата:
2017-11-14 17:14 GMT+01:00 Tom Lane <tgl@sss.pgh.pa.us>:
Peter Eisentraut <peter.eisentraut@2ndquadrant.com> writes:
> On 11/8/17 09:54, Tom Lane wrote:
>> Do procedures of this ilk belong in pg_proc at all? It seems like a large
>> fraction of the attributes tracked in pg_proc are senseless for this
>> purpose. A new catalog might be a better approach.
> The common functionality between functions and procedures is like 98%
> [citation needed], so they definitely belong there, even more so than
> aggregates, for example.
No, I don't think so. The core reason why not is that in
SELECT foo(...) FROM ...
foo() might be either a plain function or an aggregate, so it's important
that functions and aggregates share the same namespace. *That* is why
they are in the same catalog. On the other hand, since the above syntax
is not usable to call a SQL procedure, putting SQL procedures into pg_proc
just creates namespacing conflicts. Do we really want the existence of
a function foo(int) to mean that you can't create a SQL procedure named
foo and taking one int argument?
It is good point.
I agree so catalogue should be separate. Because procedures should not be used in query, then lot of attributes has not sense there. Maybe in future, we would to implement new features for procedures and it can be a problem when we share catalogue with functions.
regards, tom lane
Re: [HACKERS] SQL procedures
От:
"Daniel Verite" <daniel@manitou-mail.org>
Дата:
Tom Lane wrote: > Do we really want the existence of a function foo(int) to mean > that you can't create a SQL procedure named > foo and taking one int argument? Isn't it pretty much implied by the ALTER | DROP ROUTINE foo(...) commands where foo(...) may be either a procedure or a function? It doesn't look like it could be both. Best regards, -- Daniel Vérité PostgreSQL-powered mailer: http://www.manitou-mail.org Twitter: @DanielVerite
Re: [HACKERS] SQL procedures
От:
Simon Riggs <simon@2ndquadrant.com>
Дата:
On 14 November 2017 at 12:56, Daniel Verite wrote: > Tom Lane wrote: > >> Do we really want the existence of a function foo(int) to mean >> that you can't create a SQL procedure named >> foo and taking one int argument? > > Isn't it pretty much implied by the > ALTER | DROP ROUTINE foo(...) > commands where foo(...) may be either a procedure > or a function? It doesn't look like it could be both. It doesn't seem particularly troublesome to create another catalog table, if needed, so that shouldn't drive our thinking. It would seem to be implied by the SQLStandard that Functions and Procedures occupy the same namespace, since they are both Routines. I can't see any benefit from having foo() function AND foo() procedure at same time. It would certainly confuse most people that come from programming languages without that distinction, but maybe someone knows some Oracle-foo that I don't? -- Simon Riggs http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Re: [HACKERS] SQL procedures
От:
Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
Дата:
On 11/14/17 11:14, Tom Lane wrote: >> The common functionality between functions and procedures is like 98% >> [citation needed], so they definitely belong there, even more so than >> aggregates, for example. > No, I don't think so. The core reason why not is that in > > SELECT foo(...) FROM ... > > foo() might be either a plain function or an aggregate, so it's important > that functions and aggregates share the same namespace. *That* is why > they are in the same catalog. On the other hand, since the above syntax > is not usable to call a SQL procedure, putting SQL procedures into pg_proc > just creates namespacing conflicts. Do we really want the existence of > a function foo(int) to mean that you can't create a SQL procedure named > foo and taking one int argument? Yes, that is defined that way by the SQL standard. The point about the overlap refers more to the internals. The entire parsing, look-up, type-resolution, DDL handling, and other things are the same. So for both of these reasons I think it's appropriate to use the same catalog. -- Peter Eisentraut http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Re: [HACKERS] SQL procedures
От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Peter Eisentraut writes: > On 11/14/17 11:14, Tom Lane wrote: >> ... Do we really want the existence of >> a function foo(int) to mean that you can't create a SQL procedure named >> foo and taking one int argument? > Yes, that is defined that way by the SQL standard. Meh. OK, then it has to be one catalog. regards, tom lane
Re: [HACKERS] SQL procedures
От:
Laurenz Albe <laurenz.albe@cybertec.at>
Дата:
Simon Riggs wrote: > It would seem to be implied by the SQLStandard that Functions and > Procedures occupy the same namespace, since they are both Routines. > > I can't see any benefit from having foo() function AND foo() procedure > at same time. It would certainly confuse most people that come from > programming languages without that distinction, but maybe someone > knows some Oracle-foo that I don't? The question already has been decided on the (better) basis of the SQL standard, but for what it is worth: Oracle has functions and procedures in the same name space. Yours, Laurenz Albe
Re: [HACKERS] SQL procedures
От:
Andrew Dunstan <andrew.dunstan@2ndquadrant.com>
Дата:
On 11/14/2017 10:54 AM, Peter Eisentraut wrote: > Here is an updated patch. It's updated for the recent documentation > format changes. I added some more documentation as suggested by reviewers. > > I also added more tests about how the various privilege commands (GRANT, > GRANT on ALL, default privileges) would work with the new object type. > I had not looked at that in much detail with the previous version of the > patch, but it seems to work the way I would have wanted without any code > changes, so it's all documentation additions and new tests. > > As part of this I have also developed additional tests for how the same > privilege commands apply to aggregates, which didn't appear to be > covered yet, and I was worried that I might have broken it, which it > seems I did not. This is included in the big patch, but I have also > included it here as a separate patch, as it could be committed > independently as additional tests for existing functionality. > > It this point, this patch has no more open TODOs or > need-to-think-about-this-later's that I'm aware of. > I've been through this fairly closely, and I think it's pretty much committable. The only big item that stands out for me is the issue of OUT parameters. While returning multiple result sets will be a useful feature, it's also very common in my experience for stored procedures to have scalar out params as well. I'm not sure how we should go about providing for it, but I think we need to be sure we're not closing any doors. Here, for example, is how the MySQL stored procedure feature works with JDBC: I think it will be OK if we use cursors to return multiple result sets, along the lines of Peter's next patch, but we shouldn't regard that as the end of the story. Even if we don't provide for it in this go round we should aim at eventually providing for stored procedure OUT params. Apart from that here are a few fairly minor nitpicks: Default Privileges docs: although FUNCTIONS and ROUTINES are equivalent here, we should probably advise using ROUTINES, as FUNCTIONS could easily be take to mean "functions but not procedures". CREATE/ALTER PROCEDURE: It seems more than a little odd to allow attributes that are irrelevant to procedures in these statements. The docco states "for compatibility with ALTER FUNCTION" but why do we want such compatibility if it's meaningless? If we can manage it without too much violence I'd prefer to see an exception raised if these are used. In create_function.sgml, we have: If a schema name is included, then the function is created in the specified schema. Otherwise it is created in the current schema. - The name of the new function must not match any existing function + The name of the new function must not match any existing function or procedure with the same input argument types in the same schema. However, functions of different argument types can share a name (this is called overloading). The last sentence should probably say "functions and procedures of different argument types" There's a similar issue in create_procedure.sqml. In grant.sgml, there is: + The FUNCTION syntax also works for aggregate + functions. Or use ROUTINE to refer to a function, + aggregate function, or procedure regardless of what it is. I would replace "Or" by "Alternatively,". I think it reads better that way. In functions.c, there is: /* Should only get here for VOID functions */ - Assert(fcache->rettype == VOIDOID); + Assert(fcache->rettype == InvalidOid || fcache->rettype == VOIDOID); fcinfo->isnull = true; result = (Datum) 0; The comment should also refer to procedures. It took me a minute to work out what is going on with the new code in aclchk.c:objectsInSchemaToOids(). It probably merits a comment or two. We should document where returned values in PL procedures are ignored (plperl, pltcl) and where they are not (plpython, plpgsql). Maybe we should think about possibly being more consistent here, too. The context line here looks odd: CREATE PROCEDURE test_proc2() LANGUAGE plpythonu AS $$ return 5 $$; CALL test_proc2(); ERROR: PL/Python procedure did not return None CONTEXT: PL/Python function "test_proc2" Perhaps we need to change plpython_error_callback() so that "function" isn't hardcoded. cheers andrew -- Andrew Dunstan https://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Re: [HACKERS] SQL procedures
От:
Andrew Dunstan <andrew.dunstan@2ndquadrant.com>
Дата:
On 11/20/2017 04:25 PM, I wrote: > I've been through this fairly closely, and I think it's pretty much > committable. The only big item that stands out for me is the issue of > OUT parameters. > > While returning multiple result sets will be a useful feature, it's also > very common in my experience for stored procedures to have scalar out > params as well. I'm not sure how we should go about providing for it, > but I think we need to be sure we're not closing any doors. > > Here, for example, is how the MySQL stored procedure feature works with > JDBC: > > I think it will be OK if we use cursors to return multiple result sets, > along the lines of Peter's next patch, but we shouldn't regard that as > the end of the story. Even if we don't provide for it in this go round > we should aim at eventually providing for stored procedure OUT params. > > > Of course it's true that we could replace a scalar OUT parameter with a one row resultset if we have return of multiple resultsets from SPs. But it's different from the common use pattern and a darn sight more cumbersome to use. cheers andrew -- Andrew Dunstan https://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Re: [HACKERS] SQL procedures
От:
Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
Дата:
On 11/20/17 16:25, Andrew Dunstan wrote: > I've been through this fairly closely, and I think it's pretty much > committable. The only big item that stands out for me is the issue of > OUT parameters. I figured that that's something that would come up. I had intentionally prohibited OUT parameters for now so that we can come up with something for them without having to break any backward compatibility. From reading some of the references so far, I think it could be sufficient to return a one-row result set and have the drivers adapt the returned data into their interfaces. The only thing that would be a bit weird about that is that a CALL command with OUT parameters would return a result set and a CALL command without any OUT parameters would return CommandComplete instead. Maybe that's OK. > Default Privileges docs: although FUNCTIONS and ROUTINES are equivalent > here, we should probably advise using ROUTINES, as FUNCTIONS could > easily be take to mean "functions but not procedures". OK, I'll update the documentation a bit more. > CREATE/ALTER PROCEDURE: It seems more than a little odd to allow > attributes that are irrelevant to procedures in these statements. The > docco states "for compatibility with ALTER FUNCTION" but why do we want > such compatibility if it's meaningless? If we can manage it without too > much violence I'd prefer to see an exception raised if these are used. We can easily be more restrictive here. I'm open to suggestions. There is a difference between options that don't make sense for procedures (e.g., RETURNS NULL ON NULL INPUT), which are prohibited, and those that might make sense sometime, but are currently not used. But maybe that's too confusing and we should just prohibit options that are not currently used. > In create_function.sgml, we have: > > If a schema name is included, then the function is created in the > specified schema. Otherwise it is created in the current schema. > - The name of the new function must not match any existing function > + The name of the new function must not match any existing > function or procedure > with the same input argument types in the same schema. However, > functions of different argument types can share a name (this is > called overloading). > > The last sentence should probably say "functions and procedures of > different argument types" There's a similar issue in create_procedure.sqml. fixing that > In grant.sgml, there is: > > + The FUNCTION syntax also works for aggregate > + functions. Or use ROUTINE to refer to a > function, > + aggregate function, or procedure regardless of what it is. > > > I would replace "Or" by "Alternatively,". I think it reads better that way. fixing that > In functions.c, there is: > > /* Should only get here for VOID functions */ > - Assert(fcache->rettype == VOIDOID); > + Assert(fcache->rettype == InvalidOid || fcache->rettype > == VOIDOID); > fcinfo->isnull = true; > result = (Datum) 0; > > The comment should also refer to procedures. fixing that > It took me a minute to work out what is going on with the new code in > aclchk.c:objectsInSchemaToOids(). It probably merits a comment or two. improving that > We should document where returned values in PL procedures are ignored > (plperl, pltcl) and where they are not (plpython, plpgsql). Maybe we > should think about possibly being more consistent here, too. Yeah, suggestions? I think it makes sense in PL/pgSQL and PL/Python to disallow return values that would end up being ignored, because the only way a return value could arise is if user code explicit calls RETURN/return. However, in Perl, the return value is the result of the last statement, so prohibiting a return value would be very inconvenient. (Don't know about Tcl.) So maybe the current behavior makes sense. Documentation is surely needed. > The context line here looks odd: > > CREATE PROCEDURE test_proc2() > LANGUAGE plpythonu > AS $$ > return 5 > $$; > CALL test_proc2(); > ERROR: PL/Python procedure did not return None > CONTEXT: PL/Python function "test_proc2" > > Perhaps we need to change plpython_error_callback() so that "function" > isn't hardcoded. fixing that -- Peter Eisentraut http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Re: [HACKERS] SQL procedures
От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Peter Eisentraut writes: > On 11/20/17 16:25, Andrew Dunstan wrote: >> We should document where returned values in PL procedures are ignored >> (plperl, pltcl) and where they are not (plpython, plpgsql). Maybe we >> should think about possibly being more consistent here, too. > Yeah, suggestions? I think it makes sense in PL/pgSQL and PL/Python to > disallow return values that would end up being ignored, because the only > way a return value could arise is if user code explicit calls > RETURN/return. However, in Perl, the return value is the result of the > last statement, so prohibiting a return value would be very > inconvenient. (Don't know about Tcl.) So maybe the current behavior > makes sense. Documentation is surely needed. Tcl has the same approach as Perl: the return value of a proc is the same as the value of its last command. There's no such thing as a proc that doesn't return a value. regards, tom lane
Re: [HACKERS] SQL procedures
От:
Pavel Stehule <pavel.stehule@gmail.com>
Дата:
2017-11-22 19:01 GMT+01:00 Peter Eisentraut <peter.eisentraut@2ndquadrant.com>:
On 11/20/17 16:25, Andrew Dunstan wrote:
> I've been through this fairly closely, and I think it's pretty much
> committable. The only big item that stands out for me is the issue of
> OUT parameters.
I figured that that's something that would come up. I had intentionally
prohibited OUT parameters for now so that we can come up with something
for them without having to break any backward compatibility.
From reading some of the references so far, I think it could be
sufficient to return a one-row result set and have the drivers adapt the
returned data into their interfaces. The only thing that would be a bit
weird about that is that a CALL command with OUT parameters would return
a result set and a CALL command without any OUT parameters would return
CommandComplete instead. Maybe that's OK.
T-SQL procedures returns data or OUT variables.
I remember, it was very frustrating
Maybe first result can be reserved for OUT variables, others for multi result set
Regards
Pavel
> Default Privileges docs: although FUNCTIONS and ROUTINES are equivalent
> here, we should probably advise using ROUTINES, as FUNCTIONS could
> easily be take to mean "functions but not procedures".
OK, I'll update the documentation a bit more.
> CREATE/ALTER PROCEDURE: It seems more than a little odd to allow
> attributes that are irrelevant to procedures in these statements. The
> docco states "for compatibility with ALTER FUNCTION" but why do we want
> such compatibility if it's meaningless? If we can manage it without too
> much violence I'd prefer to see an exception raised if these are used.
We can easily be more restrictive here. I'm open to suggestions. There
is a difference between options that don't make sense for procedures
(e.g., RETURNS NULL ON NULL INPUT), which are prohibited, and those that
might make sense sometime, but are currently not used. But maybe that's
too confusing and we should just prohibit options that are not currently
used.
> In create_function.sgml, we have:
>
> If a schema name is included, then the function is created in the
> specified schema. Otherwise it is created in the current schema.
> - The name of the new function must not match any existing function
> + The name of the new function must not match any existing
> function or procedure
> with the same input argument types in the same schema. However,
> functions of different argument types can share a name (this is
> called <firstterm>overloading</firstterm>).
>
> The last sentence should probably say "functions and procedures of
> different argument types" There's a similar issue in create_procedure.sqml.
fixing that
> In grant.sgml, there is:
>
> + The <literal>FUNCTION</literal> syntax also works for aggregate
> + functions. Or use <literal>ROUTINE</literal> to refer to a
> function,
> + aggregate function, or procedure regardless of what it is.
>
>
> I would replace "Or" by "Alternatively,". I think it reads better that way.
fixing that
> In functions.c, there is:
>
> /* Should only get here for VOID functions */
> - Assert(fcache->rettype == VOIDOID);
> + Assert(fcache->rettype == InvalidOid || fcache->rettype
> == VOIDOID);
> fcinfo->isnull = true;
> result = (Datum) 0;
>
> The comment should also refer to procedures.
fixing that
> It took me a minute to work out what is going on with the new code in
> aclchk.c:objectsInSchemaToOids(). It probably merits a comment or two.
improving that
> We should document where returned values in PL procedures are ignored
> (plperl, pltcl) and where they are not (plpython, plpgsql). Maybe we
> should think about possibly being more consistent here, too.
Yeah, suggestions? I think it makes sense in PL/pgSQL and PL/Python to
disallow return values that would end up being ignored, because the only
way a return value could arise is if user code explicit calls
RETURN/return. However, in Perl, the return value is the result of the
last statement, so prohibiting a return value would be very
inconvenient. (Don't know about Tcl.) So maybe the current behavior
makes sense. Documentation is surely needed.
> The context line here looks odd:
>
> CREATE PROCEDURE test_proc2()
> LANGUAGE plpythonu
> AS $$
> return 5
> $$;
> CALL test_proc2();
> ERROR: PL/Python procedure did not return None
> CONTEXT: PL/Python function "test_proc2"
>
> Perhaps we need to change plpython_error_callback() so that "function"
> isn't hardcoded.
fixing that
--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Re: [HACKERS] SQL procedures
От:
Andrew Dunstan <andrew.dunstan@2ndquadrant.com>
Дата:
On 11/22/2017 01:10 PM, Tom Lane wrote: > Peter Eisentraut writes: >> On 11/20/17 16:25, Andrew Dunstan wrote: >>> We should document where returned values in PL procedures are ignored >>> (plperl, pltcl) and where they are not (plpython, plpgsql). Maybe we >>> should think about possibly being more consistent here, too. >> Yeah, suggestions? I think it makes sense in PL/pgSQL and PL/Python to >> disallow return values that would end up being ignored, because the only >> way a return value could arise is if user code explicit calls >> RETURN/return. However, in Perl, the return value is the result of the >> last statement, so prohibiting a return value would be very >> inconvenient. (Don't know about Tcl.) So maybe the current behavior >> makes sense. Documentation is surely needed. > Tcl has the same approach as Perl: the return value of a proc is the > same as the value of its last command. There's no such thing as a > proc that doesn't return a value. > > Right. We probably just need to document the behaviour here. I'd be satisfied with that. cheers andrew -- Andrew Dunstan https://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Re: [HACKERS] SQL procedures
От:
Corey Huinker <corey.huinker@gmail.com>
Дата:
T-SQL procedures returns data or OUT variables.I remember, it was very frustratingMaybe first result can be reserved for OUT variables, others for multi result set
It's been many years, but if I recall correctly, T-SQL returns a series of result sets, with no description of the result sets to be returned, each of which must be consumed fully before the client can move onto the next result set. Then and only then can the output parameters be read. Which was very frustrating because the OUT parameters seemed like a good place to put values for things like "result set 1 has 205 rows" and "X was false so we omitted one result set entirely" so you couldn't, y'know easily omit entire result sets.
Re: [HACKERS] SQL procedures
От:
Andrew Dunstan <andrew.dunstan@2ndquadrant.com>
Дата:
On 11/22/2017 02:39 PM, Corey Huinker wrote: > > > T-SQL procedures returns data or OUT variables. > > I remember, it was very frustrating > > Maybe first result can be reserved for OUT variables, others for > multi result set > > > It's been many years, but if I recall correctly, T-SQL returns a > series of result sets, with no description of the result sets to be > returned, each of which must be consumed fully before the client can > move onto the next result set. Then and only then can the output > parameters be read. Which was very frustrating because the OUT > parameters seemed like a good place to put values for things like > "result set 1 has 205 rows" and "X was false so we omitted one result > set entirely" so you couldn't, y'know easily omit entire result sets. > Exactly. If we want to handle OUT params this way they really need to be the first resultset for just this reason. That could possibly be done by the glue code reserving a spot in the resultset list and filling it in at the end of the procedure. cheers andrew -- Andrew Dunstan https://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Re: [HACKERS] SQL procedures
От:
Craig Ringer <craig@2ndquadrant.com>
Дата:
On 23 November 2017 at 03:47, Andrew Dunstan <andrew.dunstan@2ndquadrant.com> wrote:
Exactly. If we want to handle OUT params this way they really need to be
On 11/22/2017 02:39 PM, Corey Huinker wrote:
>
>
> T-SQL procedures returns data or OUT variables.
>
> I remember, it was very frustrating
>
> Maybe first result can be reserved for OUT variables, others for
> multi result set
>
>
> It's been many years, but if I recall correctly, T-SQL returns a
> series of result sets, with no description of the result sets to be
> returned, each of which must be consumed fully before the client can
> move onto the next result set. Then and only then can the output
> parameters be read. Which was very frustrating because the OUT
> parameters seemed like a good place to put values for things like
> "result set 1 has 205 rows" and "X was false so we omitted one result
> set entirely" so you couldn't, y'know easily omit entire result sets.
>
the first resultset for just this reason. That could possibly be done by
the glue code reserving a spot in the resultset list and filling it in
at the end of the procedure.
I fail to understand how that can work though. Wouldn't we have to buffer all the resultset contents on the server in tuplestores or similar, so we can send the parameters and then the result sets?
Isn't that going to cause a whole different set of painful difficulties instead?
What it comes down to is that if we want to see output params before result sets, but the output params are only emitted when the proc returns, then someone has to buffer. We get to choose if it's the client or the server.
Re: [HACKERS] SQL procedures
От:
Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
Дата:
On 11/23/17 00:59, Craig Ringer wrote: > Exactly. If we want to handle OUT params this way they really need to be > the first resultset for just this reason. That could possibly be done by > the glue code reserving a spot in the resultset list and filling it in > at the end of the procedure. > > I fail to understand how that can work though. Wouldn't we have to > buffer all the resultset contents on the server in tuplestores or > similar, so we can send the parameters and then the result sets? The current PoC in the other thread puts the extra result sets in cursors. That's essentially the buffer you are referring to. So it seems possible, but there are some details to be worked out. -- Peter Eisentraut http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Re: [HACKERS] SQL procedures
Here is a new patch that addresses the previous review comments. If there are no new comments, I think this might be ready to go. -- Peter Eisentraut http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Re: [HACKERS] SQL procedures
От:
Simon Riggs <simon@2ndquadrant.com>
Дата:
On 29 November 2017 at 02:03, Peter Eisentraut wrote: > Here is a new patch that addresses the previous review comments. > > If there are no new comments, I think this might be ready to go. Is ERRCODE_INVALID_FUNCTION_DEFINITION still appropriate? Other than that, looks ready to go. -- Simon Riggs http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Re: [HACKERS] SQL procedures
От:
Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
Дата:
On 11/28/17 10:34, Simon Riggs wrote: > Is ERRCODE_INVALID_FUNCTION_DEFINITION still appropriate? Well, maybe not, but changing that is likely more trouble than it's worth. -- Peter Eisentraut http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Re: [HACKERS] SQL procedures
От:
Andrew Dunstan <andrew.dunstan@2ndquadrant.com>
Дата:
On 11/28/2017 10:03 AM, Peter Eisentraut wrote: > Here is a new patch that addresses the previous review comments. > > If there are no new comments, I think this might be ready to go. > Looks good to me. Marking ready for committer. cheers andrew -- Andrew Dunstan https://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Re: [HACKERS] SQL procedures
От:
Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
Дата:
On 11/29/17 14:17, Andrew Dunstan wrote: > On 11/28/2017 10:03 AM, Peter Eisentraut wrote: >> Here is a new patch that addresses the previous review comments. >> >> If there are no new comments, I think this might be ready to go. > > Looks good to me. Marking ready for committer. committed -- Peter Eisentraut http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Re: [HACKERS] SQL procedures
От:
Thomas Munro <thomas.munro@enterprisedb.com>
Дата:
On Fri, Dec 1, 2017 at 7:48 AM, Peter Eisentraut wrote: > On 11/29/17 14:17, Andrew Dunstan wrote: >> On 11/28/2017 10:03 AM, Peter Eisentraut wrote: >>> Here is a new patch that addresses the previous review comments. >>> >>> If there are no new comments, I think this might be ready to go. >> >> Looks good to me. Marking ready for committer. > > committed postgres=# \df List of functionsSchema | Name | Result data type | Argument data types | Type --------+------+------------------+---------------------+------public | bar | integer | i integer | funcpublic | foo | | i integer | proc (2 rows) Should this now be called a "List of routines"? -- Thomas Munro http://www.enterprisedb.com
Re: [HACKERS] SQL procedures
От:
Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
Дата:
On 11/30/17 15:50, Thomas Munro wrote: > postgres=# \df > List of functions > Schema | Name | Result data type | Argument data types | Type > --------+------+------------------+---------------------+------ > public | bar | integer | i integer | func > public | foo | | i integer | proc > (2 rows) > > Should this now be called a "List of routines"? Maybe, but I hesitate to go around and change all mentions of "function" like that. That might just confuse people. -- Peter Eisentraut http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Re: [HACKERS] SQL procedures
От:
Robert Haas <robertmhaas@gmail.com>
Дата:
On Fri, Dec 1, 2017 at 9:31 AM, Peter Eisentraut wrote: > On 11/30/17 15:50, Thomas Munro wrote: >> postgres=# \df >> List of functions >> Schema | Name | Result data type | Argument data types | Type >> --------+------+------------------+---------------------+------ >> public | bar | integer | i integer | func >> public | foo | | i integer | proc >> (2 rows) >> >> Should this now be called a "List of routines"? > > Maybe, but I hesitate to go around and change all mentions of "function" > like that. That might just confuse people. Yeah, this is not unlike the problems we have deciding whether to say "relation" or "table". It's a problem that comes when most foos are bars but there are multiple types of exotic foo that are not bars. That's pretty much the case here -- most functions are probably just functions, but a few might be procedures or aggregates. I think leaving this and similar cases as "functions" is fine. I wonder whether it was really necessary for the SQL standards committee (or Oracle) to invent both procedures and functions to represent very similar things, but they did. -- Robert Haas EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company
Re: [HACKERS] SQL procedures
От:
Simon Riggs <simon@2ndquadrant.com>
Дата:
On 2 December 2017 at 01:31, Peter Eisentraut wrote: > On 11/30/17 15:50, Thomas Munro wrote: >> postgres=# \df >> List of functions >> Schema | Name | Result data type | Argument data types | Type >> --------+------+------------------+---------------------+------ >> public | bar | integer | i integer | func >> public | foo | | i integer | proc >> (2 rows) >> >> Should this now be called a "List of routines"? > > Maybe, but I hesitate to go around and change all mentions of "function" > like that. That might just confuse people. Agreed \dfn shows functions only so we might want to consider having \df say "List of functions and procedures" \dfn say "List of functions" and a new option to list procedures only \dfp say "List of procedures" -- Simon Riggs http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Re: [HACKERS] SQL procedures
От:
Robert Haas <robertmhaas@gmail.com>
Дата:
On Wed, Nov 8, 2017 at 9:21 AM, Peter Eisentraut wrote: >> Why not use VOIDOID for the prorettype value? > > We need a way to distinguish functions that are callable by SELECT and > procedures that are callable by CALL. I agree that we need this, but using prorettype = InvalidOid to do it might not be the best way, because it only works for procedures that don't return anything. If a procedure could return, say, an integer, then it would fail, because we have two ways to say that something in pg_proc returns nothing (InvalidOid, VOIDOID) but we have only one way to say that it returns an integer (INT4OID). Similarly, we'd have a problem if we ever tried to use procedures for handling triggers or (perhaps more likely) event triggers, since those special kinds of functions also signal their purpose via the return type - which may also not have been such a hot idea, but at least in those cases the idea of returning any sort of real result is more or less known to be nonsensical. Anyway, I think it would be better to invent an explicit way to represent whether something is a procedure rather than relying on overloading prorettype to tell us. -- Robert Haas EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company
Re: [HACKERS] SQL procedures
От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Robert Haas writes: > I agree that we need this, but using prorettype = InvalidOid to do it > might not be the best way, because it only works for procedures that > don't return anything. If a procedure could return, say, an integer, Good point, because that is possible in some other systems, and so somebody is going to ask for it at some point. > Anyway, I think it would be better to invent an explicit way to > represent whether something is a procedure rather than relying on > overloading prorettype to tell us. +1 --- seems like a new bool column is the thing. Or may we should merge "proisprocedure" with proisagg and proiswindow into an enum prokind? Although that would break some existing client-side code. PS: I still strongly disagree with allowing prorettype to be zero. regards, tom lane
Re: [HACKERS] SQL procedures
От:
Pavel Stehule <pavel.stehule@gmail.com>
Дата:
2018-01-02 17:47 GMT+01:00 Tom Lane <tgl@sss.pgh.pa.us>:
Robert Haas <robertmhaas@gmail.com> writes:
> I agree that we need this, but using prorettype = InvalidOid to do it
> might not be the best way, because it only works for procedures that
> don't return anything. If a procedure could return, say, an integer,
Good point, because that is possible in some other systems, and so
somebody is going to ask for it at some point.
> Anyway, I think it would be better to invent an explicit way to
> represent whether something is a procedure rather than relying on
> overloading prorettype to tell us.
+1 --- seems like a new bool column is the thing. Or may we should merge
"proisprocedure" with proisagg and proiswindow into an enum prokind?
Although that would break some existing client-side code.
+1
Pavel
PS: I still strongly disagree with allowing prorettype to be zero.
regards, tom lane
Re: [HACKERS] SQL procedures
От:
Robert Haas <robertmhaas@gmail.com>
Дата:
On Tue, Jan 2, 2018 at 11:47 AM, Tom Lane wrote: >> Anyway, I think it would be better to invent an explicit way to >> represent whether something is a procedure rather than relying on >> overloading prorettype to tell us. > > +1 --- seems like a new bool column is the thing. Or may we should merge > "proisprocedure" with proisagg and proiswindow into an enum prokind? > Although that would break some existing client-side code. Assuming that we're confident that "procedure" is mutually exclusive with "aggregate" and "window function", that seems like the right way to go. And I think that's probably the case, both because we're deciding not to let procedures be called from SELECT statements (though Oracle apparently does) and because we've chosen syntax that suggests distinctness: CREATE AGGREGATE, CREATE FUNCTION, CREATE PROCEDURE. Window functions are less distinct from the others, since they go through CREATE FUNCTION, but it still seems unlikely that we'd ever want to try to support a "window procedure". -- Robert Haas EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company
Re: [HACKERS] SQL procedures
От:
Andrew Dunstan <andrew.dunstan@2ndquadrant.com>
Дата:
On 01/02/2018 01:45 PM, Robert Haas wrote: > On Tue, Jan 2, 2018 at 11:47 AM, Tom Lane wrote: >>> Anyway, I think it would be better to invent an explicit way to >>> represent whether something is a procedure rather than relying on >>> overloading prorettype to tell us. >> +1 --- seems like a new bool column is the thing. Or may we should merge >> "proisprocedure" with proisagg and proiswindow into an enum prokind? >> Although that would break some existing client-side code. > Assuming that we're confident that "procedure" is mutually exclusive > with "aggregate" and "window function", that seems like the right way > to go. And I think that's probably the case, both because we're > deciding not to let procedures be called from SELECT statements > (though Oracle apparently does) and because we've chosen syntax that > suggests distinctness: CREATE AGGREGATE, CREATE FUNCTION, CREATE > PROCEDURE. Window functions are less distinct from the others, since > they go through CREATE FUNCTION, but it still seems unlikely that we'd > ever want to try to support a "window procedure". > Yeah, but these things don't feel like they belong in the same category. The fact that we have to ask this question is a symptom of that. A boolean feels more natural to me here, although I acknowledge it will result in a tiny amount of catalog bloat. Tom's point about client-side code is also valid. I don't feel very strongly about it, though. cheers andrew -- Andrew Dunstan https://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Re: [HACKERS] SQL procedures
От:
Robert Haas <robertmhaas@gmail.com>
Дата:
On Tue, Jan 2, 2018 at 1:57 PM, Andrew Dunstan wrote: > Yeah, but these things don't feel like they belong in the same category. > The fact that we have to ask this question is a symptom of that. Well, that's got to be asked about any representation we choose - that question is the motivation for not liking the use of prorettype for this purpose, so it's only fair to ask whether any alternative has the same problem. > A > boolean feels more natural to me here, although I acknowledge it will > result in a tiny amount of catalog bloat. Tom's point about client-side > code is also valid. I don't feel very strongly about it, though. I think the catalog bloat is too minor to care about, but if these things really are mutually exclusive, it's more natural to have them use a single flag character rather than a series of Booleans. Otherwise, it may be unclear to the casual observer (or hacker) that at most one of the Booleans can be true, possibly leading to user confusion (or bugs). It's pretty well impossible to introduce new features without occasionally changing the catalog representation. We had several people grumble when I replaced relistemp with relpersistence, and we (rightly, IMHO) told those people to suck it up and deal. I don't think we should react any differently here. I recognize that it's a pain, but it's not that much of a pain, and it may even be helpful to tool authors who actually need to handle procedures differently than functions, which is probably a lot of them. pgAdmin for example seems like it will certainly need to care. -- Robert Haas EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company
Re: [HACKERS] SQL procedures
От:
Andrew Dunstan <andrew.dunstan@2ndquadrant.com>
Дата:
On 01/02/2018 02:14 PM, Robert Haas wrote: > On Tue, Jan 2, 2018 at 1:57 PM, Andrew Dunstan > wrote: >> Yeah, but these things don't feel like they belong in the same category. >> The fact that we have to ask this question is a symptom of that. > Well, that's got to be asked about any representation we choose - that > question is the motivation for not liking the use of prorettype for > this purpose, so it's only fair to ask whether any alternative has the > same problem. I think there's broad agreement about not liking use of prorettype for this purpose. > >> A >> boolean feels more natural to me here, although I acknowledge it will >> result in a tiny amount of catalog bloat. Tom's point about client-side >> code is also valid. I don't feel very strongly about it, though. > I think the catalog bloat is too minor to care about, but if these > things really are mutually exclusive, it's more natural to have them > use a single flag character rather than a series of Booleans. > Otherwise, it may be unclear to the casual observer (or hacker) that > at most one of the Booleans can be true, possibly leading to user > confusion (or bugs). Fair point. I don't recall if we discussed anything like this when window functions were introduced. > > It's pretty well impossible to introduce new features without > occasionally changing the catalog representation. We had several > people grumble when I replaced relistemp with relpersistence, and we > (rightly, IMHO) told those people to suck it up and deal. I don't > think we should react any differently here. I recognize that it's a > pain, but it's not that much of a pain, and it may even be helpful to > tool authors who actually need to handle procedures differently than > functions, which is probably a lot of them. pgAdmin for example seems > like it will certainly need to care. I agree. cheers andrew -- Andrew Dunstan https://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Re: [HACKERS] SQL procedures
От:
Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
Дата:
On 1/2/18 11:47, Tom Lane wrote: > +1 --- seems like a new bool column is the thing. Or may we should merge > "proisprocedure" with proisagg and proiswindow into an enum prokind? > Although that would break some existing client-side code. prokind sounds good. I'll look into that. -- Peter Eisentraut http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Re: [HACKERS] SQL procedures
On 1/2/18 17:47, Peter Eisentraut wrote: > On 1/2/18 11:47, Tom Lane wrote: >> +1 --- seems like a new bool column is the thing. Or may we should merge >> "proisprocedure" with proisagg and proiswindow into an enum prokind? >> Although that would break some existing client-side code. > > prokind sounds good. I'll look into that. Here is a patch set for that. (I just kept the pg_proc.h changes separate for easier viewing.) It's not quite complete; some frontend code still needs adjusting; but the idea is clear. I think this would be a pretty good change. It doesn't appear to save a ton amount of code, although a couple of cases where inconsistent settings of proisagg and proiswindow had to be handed could be removed. Because window functions are a separate kind in pg_proc but not in the object address system, inconsistencies will remain in the system, but I guess that's just the way it is. -- Peter Eisentraut http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
prokind column (was Re: [HACKERS] SQL procedures)
On 1/9/18 13:08, Peter Eisentraut wrote: > On 1/2/18 17:47, Peter Eisentraut wrote: >> On 1/2/18 11:47, Tom Lane wrote: >>> +1 --- seems like a new bool column is the thing. Or may we should merge >>> "proisprocedure" with proisagg and proiswindow into an enum prokind? >>> Although that would break some existing client-side code. >> >> prokind sounds good. I'll look into that. > > Here is a patch set for that. (I just kept the pg_proc.h changes > separate for easier viewing.) It's not quite complete; some frontend > code still needs adjusting; but the idea is clear. > > I think this would be a pretty good change. It doesn't appear to save a > ton amount of code, although a couple of cases where inconsistent > settings of proisagg and proiswindow had to be handed could be removed. > Because window functions are a separate kind in pg_proc but not in the > object address system, inconsistencies will remain in the system, but I > guess that's just the way it is. Here is this patch updated. The client changes are now complete and all the tests pass. I have also rolled back the places where the code used prorettype to detect procedures and replaced this by the new facility. -- Peter Eisentraut http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Re: prokind column (was Re: [HACKERS] SQL procedures)
От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Peter Eisentraut writes: > Here is this patch updated. The client changes are now complete and all > the tests pass. I have also rolled back the places where the code used > prorettype to detect procedures and replaced this by the new facility. I took a quick look through this and noted a few small problems; the only one worth mentioning here is that you've broken psql tab completion for functions and aggregates when talking to a pre-v11 server. I don't think that's acceptable; however, since tab-complete.c has no existing provisions for adjusting its queries based on server version, it's not really clear what to do to fix it. I'm sure that's soluble (and I think I recall a recent thread bumping up against the same problem for another change), but it needs a bit more sweat. We need a plan for when/how to apply this, along with the proposed bootstrap data conversion patch, which obviously conflicts with it significantly. Looking through the stuff pending in next month's commitfest, we are fortunate in that only a few of those patches seem to need to touch pg_proc.h at all, and none have really large deltas AFAICS (I might've missed something though). I propose proceeding as follows: 1. Get this patch in as soon as we can resolve its remaining weak spots. That will force rebasing of pending patches that touch pg_proc.h, but I don't think it'll be painful, since the needed changes are pretty small and obvious. 2. During the March commitfest, adjust the bootstrap data conversion patch to handle this change, and review it generally. 3. At the end of the 'fest, or whenever we've dealt with all other patches that need to touch the bootstrap source data, apply the data conversion patch. My thought here is that the data conversion patch is going to break basically every pending patch that touches src/include/catalog/, so we ought to apply it at a point where that list of patches is short and there's lots of time for people to redo them. Hence, end of the dev cycle is the right time. regards, tom lane
Re: prokind column (was Re: [HACKERS] SQL procedures)
От:
John Naylor <jcnaylor@gmail.com>
Дата:
On 2/25/18, Tom Lane wrote: > We need a plan for when/how to apply this, along with the proposed > bootstrap data conversion patch, which obviously conflicts with it > significantly. The bulk changes in the bootstrap data patch are scripted rather than patched, so the prokind patch will pose little in the way of conflicts. I can't verify this just yet since Peter's second patch doesn't apply for me against c4ba1bee68ab. Also, as of version 7 my patch left out default values and human-readable oids, since I wanted to get the new generated headers reviewed and up to project standards first. Since I'll likely have to adjust the patches for those features anyway, there's plenty of room for me to adjust to the changes to pg_proc.h as well. > My thought here is that the data conversion patch is going to break > basically every pending patch that touches src/include/catalog/, > so we ought to apply it at a point where that list of patches is short > and there's lots of time for people to redo them. Hence, end of the > dev cycle is the right time. I agree. -John Naylor
Re: prokind column (was Re: [HACKERS] SQL procedures)
От:
Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
Дата:
On 2/24/18 14:08, Tom Lane wrote: > I took a quick look through this and noted a few small problems; the > only one worth mentioning here is that you've broken psql tab completion > for functions and aggregates when talking to a pre-v11 server. > I don't think that's acceptable; however, since tab-complete.c has no > existing provisions for adjusting its queries based on server version, > it's not really clear what to do to fix it. I'm sure that's soluble > (and I think I recall a recent thread bumping up against the same > problem for another change), but it needs a bit more sweat. The patches proposed in the thread "PATCH: psql tab completion for SELECT" appear to add support for version-dependent tab completion, so this could be resolved "later". -- Peter Eisentraut http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Re: prokind column (was Re: [HACKERS] SQL procedures)
От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Peter Eisentraut writes: > On 2/24/18 14:08, Tom Lane wrote: >> I took a quick look through this and noted a few small problems; the >> only one worth mentioning here is that you've broken psql tab completion >> for functions and aggregates when talking to a pre-v11 server. >> I don't think that's acceptable; however, since tab-complete.c has no >> existing provisions for adjusting its queries based on server version, >> it's not really clear what to do to fix it. I'm sure that's soluble >> (and I think I recall a recent thread bumping up against the same >> problem for another change), but it needs a bit more sweat. > The patches proposed in the thread "PATCH: psql tab completion for > SELECT" appear to add support for version-dependent tab completion, so > this could be resolved "later". I'm not sure that other patch will get in; AFAICS it's incomplete and rather controversial. But I guess we could put this issue on the open-items list so we don't forget. Anyway, once the release dust settles, I'll try to do a proper review of this patch. It'd be good if we could get it in this week before the CF starts, so that any affected patches could be rebased. regards, tom lane
Re: prokind column (was Re: [HACKERS] SQL procedures)
On Mon, Feb 26, 2018 at 02:03:19PM -0500, Tom Lane wrote:
> I'm not sure that other patch will get in; AFAICS it's incomplete and
> rather controversial. But I guess we could put this issue on the
> open-items list so we don't forget.
+1. We already know that we want to do a switch to prokind anyway,
while the other patch is still pending (don't think much about it
myself, I would just recommend users to use a version of psql matching
the one of the server instead of putting an extra load of maintenance
into psql for years to come). So I would recommend to push forward with
this one and fix what we know we have to fix, then request a rebase. We
gain nothing by letting things in a semi-broken state. I'll be happy to
help those folks rebase and/or write the patch to update psql's tab
completion for prokind as need be.
> Anyway, once the release dust settles, I'll try to do a proper review
> of this patch. It'd be good if we could get it in this week before
> the CF starts, so that any affected patches could be rebased.
Here is some input from me. I don't like either that prorettype is used
to determine if the object used is a procedure or a function. The patch
series is very sensitive to changes in pg_proc.h, still those apply
correctly when using bc1adc65 as base commit.
The original commit adding support for procedures had this diff in
clauses.c:
@@ -4401,6 +4401,7 @@ inline_function(Oid funcid, Oid result_type, Oid result_collid,
if (funcform->prolang != SQLlanguageId ||
funcform->prosecdef ||
funcform->proretset ||
+ funcform->prorettype == InvalidOid ||
funcform->prorettype == RECORDOID ||
Perhaps this should be replaced with a check on prokind?
It seems to me that the same applies to fmgr_sql_validator(). In
information_schema.sql, type_udt_catalog uses a similar comparison so
this should have a comment about why using prorettype makes more sense.
In short for all those tings, it is fine to use prorettype when directly
working on the result type, like what is done in plperl and plpython.
For all the code paths working on the object type, I think that using
prokind should be the way to go.
getProcedureTypeDescription() should use an enum instead, complaining
with elog(ERROR) if the type found is something else?
I think that get_func_isagg should be dropped and replaced by
get_func_prokind.
--
Michael
Re: prokind column (was Re: [HACKERS] SQL procedures)
От:
Catalin Iacob <iacobcatalin@gmail.com>
Дата:
On Tue, Feb 27, 2018 at 4:03 AM, Michael Paquier wrote: > I would just recommend users to use a version of psql matching > the one of the server instead of putting an extra load of maintenance > into psql for years to come Breaking tab completion in new psql against old servers might be acceptable as it's a fringe feature, but I don't think your recommendation of matching versions is practical. Lots of people manage multiple server versions and using the latest psql for all of them is currently, as far as I know, a perfectly supported way of doing that, getting new psql features and keeping compatibility. I think it would be a pity to loose that.
Re: prokind column (was Re: [HACKERS] SQL procedures)
От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Catalin Iacob writes: > On Tue, Feb 27, 2018 at 4:03 AM, Michael Paquier wrote: >> I would just recommend users to use a version of psql matching >> the one of the server instead of putting an extra load of maintenance >> into psql for years to come > Breaking tab completion in new psql against old servers might be > acceptable as it's a fringe feature, but I don't think your > recommendation of matching versions is practical. Lots of people > manage multiple server versions and using the latest psql for all of > them is currently, as far as I know, a perfectly supported way of > doing that, getting new psql features and keeping compatibility. I > think it would be a pity to loose that. We support the various psql/describe.c features against old servers, so it would be quite inconsistent for tab completion not to work similarly. There are some gaps in that already, as per the other thread, but we should clean those up not add more. regards, tom lane
Re: prokind column (was Re: [HACKERS] SQL procedures)
On Tue, Feb 27, 2018 at 11:50:31AM -0500, Tom Lane wrote: > We support the various psql/describe.c features against old servers, > so it would be quite inconsistent for tab completion not to work > similarly. There are some gaps in that already, as per the other > thread, but we should clean those up not add more. I'll try to study this thread a bit more as I lack context. So I'll reply there. What I am scared of is that Tomas Munro has done a heroic effort to increase the readability of psql's tab completion during the dev cycle of 9.6. And it would be sad to reduce the quality of this code. -- Michael
Re: prokind column (was Re: [HACKERS] SQL procedures)
Michael Paquier writes:
> Here is some input from me. ...
I have reviewed this patch and attach an updated version below.
I've rebased it up to today, fixed a few minor errors, and adopted
most of Michael's suggestions. Also, since I remain desperately
unhappy with putting zeroes into prorettype, I changed it to not
do that ;-) ... now procedures have VOIDOID as their prorettype,
and it will be substantially less painful to allow them to return
some other scalar result in future, should we wish to. I believe
I've found all the places that were relying on prorettype == 0 as
a substitute for prokind == 'p'.
I have not touched the tab-complete.c changes. It doesn't really make
sense to worry about that until we see what comes out of the other thread
discussing support for server-version-sensitive tab completion. In the
meantime let's just add an open-item entry reminding us to do something
about it before v11 freezes.
Rather than manually audit the 0002 patch, I made a brain-dead little
Perl script to convert the DATA lines automatically, and attach it
below. If pg_proc.h moves further before this gets committed, the
script could be used to generate an updated 0002 patch.
One point worth noting is that in the attached, I made some edits to
pl_gram.y to preserve the existing handling of RETURN-with-a-value
in a plpgsql procedure. However, that existing handling is pretty
stupid. If we simply drop the pl_gram.y diffs below, what happens
is that RETURN-with-a-value is complained of at compile time not
execution time, which seems far superior to me (and more like what
happens in a normal function returning VOID). I think we should
do that and adjust the regression tests accordingly, but I have not
done the latter here.
I also wonder whether we should drop the stanza at the start of
pg_get_function_result() that causes it to return NULL for a procedure.
Without that, it would now return "void" which I think is at least
as defensible, and certainly more upward-compatible with any future
extension in that area. (I did make some changes in the
information_schema that cause it to report "void" not NULL in the
same case.)
Other than those points, I think this is committable, and I think we
should get it in quickly.
regards, tom lane
diff --git a/doc/src/sgml/catalogs.sgml b/doc/src/sgml/catalogs.sgml
index 71e20f2..a0e6d70 100644
*** a/doc/src/sgml/catalogs.sgml
--- b/doc/src/sgml/catalogs.sgml
*************** SCRAM-SHA-256$<iteration
*** 5062,5076 ****
! The catalog pg_proc stores information about functions (or procedures).
! See
! and for more information.
! The table contains data for aggregate functions as well as plain functions.
! If proisagg is true, there should be a matching
! row in pg_aggregate.
Re: prokind column (was Re: [HACKERS] SQL procedures)
От:
Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
Дата:
On 2/28/18 15:45, Tom Lane wrote: > I have reviewed this patch and attach an updated version below. > I've rebased it up to today, fixed a few minor errors, and adopted > most of Michael's suggestions. Also, since I remain desperately > unhappy with putting zeroes into prorettype, I changed it to not > do that ;-) ... now procedures have VOIDOID as their prorettype, > and it will be substantially less painful to allow them to return > some other scalar result in future, should we wish to. I believe > I've found all the places that were relying on prorettype == 0 as > a substitute for prokind == 'p'. I have just posted "INOUT parameters in procedures", which contains some of those same changes. So I think we're on the same page. I will work on consolidating this. -- Peter Eisentraut http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Re: prokind column (was Re: [HACKERS] SQL procedures)
On Wed, Feb 28, 2018 at 05:37:11PM -0500, Peter Eisentraut wrote: > On 2/28/18 15:45, Tom Lane wrote: >> I have reviewed this patch and attach an updated version below. >> I've rebased it up to today, fixed a few minor errors, and adopted >> most of Michael's suggestions. Also, since I remain desperately >> unhappy with putting zeroes into prorettype, I changed it to not >> do that ;-) ... now procedures have VOIDOID as their prorettype, >> and it will be substantially less painful to allow them to return >> some other scalar result in future, should we wish to. I believe >> I've found all the places that were relying on prorettype == 0 as >> a substitute for prokind == 'p'. > > I have just posted "INOUT parameters in procedures", which contains some > of those same changes. So I think we're on the same page. I will work > on consolidating this. Thanks Peter. I have read the patch set that Tom has posted here and hunted for other inconsistencies. It seems to me that you have spotted everything. The changes in ProcedureCreate() are nice. I was wondering as well if it would be worth checking the contents of pg_proc with prorettype = 0 in the regression tests to always make sure that this never happens... Until I saw that opr_sanity.sql was actually doing already that so procedures actually are breaking that check on HEAD. -- Michael
Re: prokind column (was Re: [HACKERS] SQL procedures)
От:
Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
Дата:
On 2/28/18 17:37, Peter Eisentraut wrote: > On 2/28/18 15:45, Tom Lane wrote: >> I have reviewed this patch and attach an updated version below. >> I've rebased it up to today, fixed a few minor errors, and adopted >> most of Michael's suggestions. Also, since I remain desperately >> unhappy with putting zeroes into prorettype, I changed it to not >> do that ;-) ... now procedures have VOIDOID as their prorettype, >> and it will be substantially less painful to allow them to return >> some other scalar result in future, should we wish to. I believe >> I've found all the places that were relying on prorettype == 0 as >> a substitute for prokind == 'p'. > > I have just posted "INOUT parameters in procedures", which contains some > of those same changes. So I think we're on the same page. I will work > on consolidating this. Committed this so far. More to come on touching this up. -- Peter Eisentraut http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services