[HACKERS] proposal: PLpgSQL parallel assignemnt
[HACKERS] proposal: PLpgSQL parallel assignemnt
От:
Pavel Stehule <pavel.stehule@gmail.com>
Дата:
Hi
Some modern or old languages (GO, Lua, CLU) has similarly designed function OUT parameters like PLpgSQL.
In these languages is usually supported parallel assignment. It is not supported by PLpgSQL - there is workaround - using SELECT FROM, but it is workaround. The implementation of PA is trivial.
Current state:
==========
CREATE OR REPLACE FUNCTION fx(OUT a int, OUT b int)
AS $$ ...
possibilities of CALL and assignment
recvar := fx();
rowvar := fx();
SELECT * FROM fx() INTO a, b;
Lua, Golang like proposal:
a, b := fx();
Comments, notes, ideas?
Regards
Pavel
Re: [HACKERS] proposal: PLpgSQL parallel assignemnt
От:
Craig Ringer <craig@2ndquadrant.com>
Дата:
On 2 June 2017 at 15:51, Pavel Stehule wrote: > a, b := fx(); > > Comments, notes, ideas? I'd be pretty happy to have (a, b) = (x, y); (a, b) = f(x); which is SQL-esque. But what, if anything, does Ada do? -- Craig Ringer http://www.2ndQuadrant.com/PostgreSQL Development, 24x7 Support, Training & Services
Re: [HACKERS] proposal: PLpgSQL parallel assignemnt
От:
Pavel Stehule <pavel.stehule@gmail.com>
Дата:
2017-06-02 10:06 GMT+02:00 Craig Ringer <craig@2ndquadrant.com>:
On 2 June 2017 at 15:51, Pavel Stehule <pavel.stehule@gmail.com> wrote:
> a, b := fx();
>
> Comments, notes, ideas?
I'd be pretty happy to have
(a, b) = (x, y);
(a, b) = f(x);
which is SQL-esque.
This is not too far to my proposal - and it is fully adequate alternative.
But what, if anything, does Ada do?
What I know, no, Ada has not this statement - but the design of OUT parameters in Ada absolutely different than PostgreSQL - so in this case we cannot to use Ada language as our base :(
Regards
Pavel
--
Craig Ringer http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services
Re: [HACKERS] proposal: PLpgSQL parallel assignemnt
От:
Pavel Stehule <pavel.stehule@gmail.com>
Дата:
2017-06-02 10:15 GMT+02:00 Pavel Stehule <pavel.stehule@gmail.com>:
2017-06-02 10:06 GMT+02:00 Craig Ringer <craig@2ndquadrant.com>:On 2 June 2017 at 15:51, Pavel Stehule <pavel.stehule@gmail.com> wrote:
> a, b := fx();
>
> Comments, notes, ideas?
I'd be pretty happy to have
(a, b) = (x, y);
(a, b) = f(x);
which is SQL-esque.This is not too far to my proposal - and it is fully adequate alternative.
The ANSI form is related to SET or UPDATE commands - so in this case I see classic languages style https://en.wikipedia.org/wiki/Assignment_(computer_science) better. The assign statement in PLpgSQL is not related to embedded SQL. If we introduce SQL syntax and SET commands for schema variables then ( ) syntax is perfect, but for := PLpgSQL I am not sure
It is maybe strange, but
SET (a,b) = (SELECT a,b FROM foo)
a, b := fx()
are sentences from two independent worlds and different syntax can be correct (depends how much we would to integrate procedural and SQL worlds .. 100% T-SQL, 80% SQL/PSM, ..20% PLpgSQL or 5%PL/SQL)
Regards
Pavel
But what, if anything, does Ada do?What I know, no, Ada has not this statement - but the design of OUT parameters in Ada absolutely different than PostgreSQL - so in this case we cannot to use Ada language as our base :(RegardsPavel
--
Craig Ringer http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services
Re: [HACKERS] proposal: PLpgSQL parallel assignemnt
От:
Pavel Stehule <pavel.stehule@gmail.com>
Дата:
2017-06-02 19:05 GMT+02:00 Pavel Stehule <pavel.stehule@gmail.com>:
2017-06-02 10:15 GMT+02:00 Pavel Stehule <pavel.stehule@gmail.com>:2017-06-02 10:06 GMT+02:00 Craig Ringer <craig@2ndquadrant.com>:On 2 June 2017 at 15:51, Pavel Stehule <pavel.stehule@gmail.com> wrote:
> a, b := fx();
>
> Comments, notes, ideas?
I'd be pretty happy to have
(a, b) = (x, y);
(a, b) = f(x);
which is SQL-esque.This is not too far to my proposal - and it is fully adequate alternative.The ANSI form is related to SET or UPDATE commands - so in this case I see classic languages style https://en.wikipedia.org/wiki/Assignment_(computer_science) better. The assign statement in PLpgSQL is not related to embedded SQL. If we introduce SQL syntax and SET commands for schema variables then ( ) syntax is perfect, but for := PLpgSQL I am not sure It is maybe strange, butSET (a,b) = (SELECT a,b FROM foo)a, b := fx()are sentences from two independent worlds and different syntax can be correct (depends how much we would to integrate procedural and SQL worlds .. 100% T-SQL, 80% SQL/PSM, ..20% PLpgSQL or 5%PL/SQL)
More thoughts:
1. syntax (a,b) := f() ... can mean - assign record to temporary composite (a,b)
2. syntax a,b := f() ... can mean - unpack result composite and assign to a, b fields
so both syntaxes has sense although we don't introduce relation to SQL - on this way
a,b := 10, 20 -- ok .. attach a=c1, b=c2
a,b := (10,20) -- ok .. attach a = r.c1, b = r.c2
(a,b) := (10,20) -- ok attach ct = rt
(a,b) := 10,20 -- ok attach ct = row(c1, c2)
@1 syntax says "create composite target", @2 syntax says "unpack result". Both should to work. Personally I prefer @1 .. due less parenthesis
Regards
Pavel
RegardsPavel
But what, if anything, does Ada do?What I know, no, Ada has not this statement - but the design of OUT parameters in Ada absolutely different than PostgreSQL - so in this case we cannot to use Ada language as our base :(RegardsPavel
--
Craig Ringer http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services