Re: proposal for 8.3: Simultaneous assignment for PL/pgSQL

Lists: pgsql-hackers
From: "Pavel Stehule" <pavel(dot)stehule(at)hotmail(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Cc: andrew(at)dunslane(dot)net
Subject: proposal for 8.3: Simultaneous assignment for PL/pgSQL
Date: 2006-08-07 08:07:59
Message-ID: BAY20-F232D7195519EA3B8E0E288F9570@phx.gbl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hello

I suggest enhance plpgsq to simultaneous assignment. Main reason is missing
parameter passing by reference and less readable getting values from
functions with OUT parameters.

Currently I have to write SELECT: SELECT INTO a,b,c out3fce(1)

a,b,c := out3fce(1); -- Simultaneous assignment

Any comments?

Regards
Pavel Stehule

_________________________________________________________________
Najdete si svou lasku a nove pratele na Match.com. http://www.msn.cz/


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Pavel Stehule" <pavel(dot)stehule(at)hotmail(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org, andrew(at)dunslane(dot)net
Subject: Re: proposal for 8.3: Simultaneous assignment for PL/pgSQL
Date: 2006-08-07 12:25:23
Message-ID: 19354.1154953523@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

"Pavel Stehule" <pavel(dot)stehule(at)hotmail(dot)com> writes:
> a,b,c := out3fce(1); -- Simultaneous assignment

I thought we rejected that idea once already, on the grounds that it
would make it too hard to tell the difference between intended code
and typos.

regards, tom lane


From: andrew(at)dunslane(dot)net
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "Pavel Stehule" <pavel(dot)stehule(at)hotmail(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: proposal for 8.3: Simultaneous assignment for
Date: 2006-08-07 12:37:18
Message-ID: 2271.24.211.165.134.1154954238.squirrel@www.dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Tom Lane wrote:
> "Pavel Stehule" <pavel(dot)stehule(at)hotmail(dot)com> writes:
>> a,b,c := out3fce(1); -- Simultaneous assignment
>
> I thought we rejected that idea once already, on the grounds that it
> would make it too hard to tell the difference between intended code
> and typos.
>

In any case, I had some questions:

. is it compatible with PLSQL?
. can the effect be achieved by assigning to a composite?

cheers

andrew


From: "Pavel Stehule" <pavel(dot)stehule(at)hotmail(dot)com>
To: tgl(at)sss(dot)pgh(dot)pa(dot)us
Cc: pgsql-hackers(at)postgresql(dot)org, andrew(at)dunslane(dot)net
Subject: Re: proposal for 8.3: Simultaneous assignment for PL/pgSQL
Date: 2006-08-07 13:29:23
Message-ID: BAY20-F255534E7F6F599B584B490F9570@phx.gbl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

>
>"Pavel Stehule" <pavel(dot)stehule(at)hotmail(dot)com> writes:
> > a,b,c := out3fce(1); -- Simultaneous assignment
>
>I thought we rejected that idea once already, on the grounds that it
>would make it too hard to tell the difference between intended code
>and typos.
>

Yes, because wasn't procedures with out params, my arguments wasn't strong.
Older patch was too liberal. I can test equal type compatibility, count of
variables and fileds in record compatibility.

Pavel Stehule

_________________________________________________________________
Emotikony a pozadi programu MSN Messenger ozivi vasi konverzaci.
http://messenger.msn.cz/


From: "Pavel Stehule" <pavel(dot)stehule(at)hotmail(dot)com>
To: andrew(at)dunslane(dot)net, tgl(at)sss(dot)pgh(dot)pa(dot)us
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: proposal for 8.3: Simultaneous assignment for PL/pgSQL
Date: 2006-08-07 14:11:48
Message-ID: BAY20-F81A5372970215FA984CD2F9570@phx.gbl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

>
>Tom Lane wrote:
> > "Pavel Stehule" <pavel(dot)stehule(at)hotmail(dot)com> writes:
> >> a,b,c := out3fce(1); -- Simultaneous assignment
> >
> > I thought we rejected that idea once already, on the grounds that it
> > would make it too hard to tell the difference between intended code
> > and typos.
> >
>
>In any case, I had some questions:
>
>. is it compatible with PLSQL?

what I know no, but PLSQL has different mechanism for calling procedures.
And first of all it knows references to variables.

>. can the effect be achieved by assigning to a composite?
>

yes. I can use record type. But here is problem with less readability

The best of is implementation of CALL statement, where I can transmit values
"by" references. But it's not possible in Postgres :-(. I can't to select
unambiguously called procedure. "I can, if I accept SQL Server syntax, where
caller specify OUT, INOUT, IN flags too". I am unhappy with current
situation, and I search good solution. Simultaneous assignment is simplest.

Regards
Pavel Stehule

_________________________________________________________________
Emotikony a pozadi programu MSN Messenger ozivi vasi konverzaci.
http://messenger.msn.cz/


From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: Pavel Stehule <pavel(dot)stehule(at)hotmail(dot)com>
Cc: andrew(at)dunslane(dot)net, tgl(at)sss(dot)pgh(dot)pa(dot)us, pgsql-hackers(at)postgresql(dot)org
Subject: Re: proposal for 8.3: Simultaneous assignment for PL/pgSQL
Date: 2006-08-07 14:36:43
Message-ID: 20060807143643.GA26747@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Mon, Aug 07, 2006 at 04:11:48PM +0200, Pavel Stehule wrote:
> The best of is implementation of CALL statement, where I can transmit
> values "by" references. But it's not possible in Postgres :-(. I can't to
> select unambiguously called procedure. "I can, if I accept SQL Server
> syntax, where caller specify OUT, INOUT, IN flags too". I am unhappy with
> current situation, and I search good solution. Simultaneous assignment is
> simplest.

Well, you can implement it. After all, the CALL syntax is merely
syntactic sugar. You could (if you wanted to) do the following:

CREATE FUNCTION foo( a TEXT IN, b TEXT INOUT, c TEXT OUT ) as blah...

And in a pl/pgsql function, translate: "CALL foo(a,b,c)"
into "(b,c) = foo(a,b)" internally.

Doesn't seem like that would be too hard.

Have anice day,
--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Martijn van Oosterhout <kleptog(at)svana(dot)org>
Cc: Pavel Stehule <pavel(dot)stehule(at)hotmail(dot)com>, andrew(at)dunslane(dot)net, pgsql-hackers(at)postgresql(dot)org
Subject: Re: proposal for 8.3: Simultaneous assignment for PL/pgSQL
Date: 2006-08-07 17:11:40
Message-ID: 2921.1154970700@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Martijn van Oosterhout <kleptog(at)svana(dot)org> writes:
> Well, you can implement it. After all, the CALL syntax is merely
> syntactic sugar. You could (if you wanted to) do the following:

> CREATE FUNCTION foo( a TEXT IN, b TEXT INOUT, c TEXT OUT ) as blah...

> And in a pl/pgsql function, translate: "CALL foo(a,b,c)"
> into "(b,c) = foo(a,b)" internally.

No, Pavel's right: that doesn't work because it's ambiguous. How do you
tell whether "CALL foo(a,b,c)" means

a,b,c := foo();
b,c := foo(a);
c := foo(a,b);
select foo(a,b,c);

There could be functions foo matching all four interpretations.

regards, tom lane


From: "Pavel Stehule" <pavel(dot)stehule(at)hotmail(dot)com>
To: tgl(at)sss(dot)pgh(dot)pa(dot)us, kleptog(at)svana(dot)org
Cc: andrew(at)dunslane(dot)net, pgsql-hackers(at)postgresql(dot)org
Subject: Re: proposal for 8.3: Simultaneous assignment for PL/pgSQL
Date: 2006-08-07 17:32:37
Message-ID: BAY20-F2301F636CDDADE6DF46DABF9570@phx.gbl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

>
>Martijn van Oosterhout <kleptog(at)svana(dot)org> writes:
> > Well, you can implement it. After all, the CALL syntax is merely
> > syntactic sugar. You could (if you wanted to) do the following:
>
> > CREATE FUNCTION foo( a TEXT IN, b TEXT INOUT, c TEXT OUT ) as blah...
>
> > And in a pl/pgsql function, translate: "CALL foo(a,b,c)"
> > into "(b,c) = foo(a,b)" internally.
>
>No, Pavel's right: that doesn't work because it's ambiguous. How do you
>tell whether "CALL foo(a,b,c)" means
>
> a,b,c := foo();
> b,c := foo(a);
> c := foo(a,b);
> select foo(a,b,c);
>
>There could be functions foo matching all four interpretations.

we can do some hints:

CALL foo(a, OUT b, OUT c)

it's better than nothing

comments?

Regards
Pavel Stehule

_________________________________________________________________
Citite se osamele? Poznejte nekoho vyjmecneho diky Match.com.
http://www.msn.cz/


From: "Pavel Stehule" <pavel(dot)stehule(at)hotmail(dot)com>
To: andrew(at)dunslane(dot)net, tgl(at)sss(dot)pgh(dot)pa(dot)us
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: proposal for 8.3: Simultaneous assignment for PL/pgSQL
Date: 2006-08-08 15:17:03
Message-ID: BAY20-F25A7389AF975C311CA87F6F9540@phx.gbl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


>Tom Lane wrote:
> > "Pavel Stehule" <pavel(dot)stehule(at)hotmail(dot)com> writes:
> >> a,b,c := out3fce(1); -- Simultaneous assignment
> >
> > I thought we rejected that idea once already, on the grounds that it
> > would make it too hard to tell the difference between intended code
> > and typos.
> >
>
>In any case, I had some questions:
>
>. is it compatible with PLSQL?
>. can the effect be achieved by assigning to a composite?

I looked into SQL2003, and SQL2003 knows it (SQL/PSM):

<assignment statement> ::=
<singleton variable assignment>
| <multiple variable assignment>
<multiple variable assignment> ::=
SET <assignment target list> <equals operator> <assigned row>
<assignment target list> ::=
<left paren> <assignment target> [ { <comma> <assignment target> }... ]
<right paren>
<singleton variable assignment> ::=
SET <assignment target> <equals operator> <assignment source>

Regards
Pavel Stehule

_________________________________________________________________
Citite se osamele? Poznejte nekoho vyjmecneho diky Match.com.
http://www.msn.cz/


From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Pavel Stehule <pavel(dot)stehule(at)hotmail(dot)com>
Cc: tgl(at)sss(dot)pgh(dot)pa(dot)us, pgsql-hackers(at)postgresql(dot)org
Subject: Re: proposal for 8.3: Simultaneous assignment for PL/pgSQL
Date: 2006-08-08 15:24:51
Message-ID: 44D8ACC3.6070408@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Pavel Stehule wrote:
>
>> Tom Lane wrote:
>> > "Pavel Stehule" <pavel(dot)stehule(at)hotmail(dot)com> writes:
>> >> a,b,c := out3fce(1); -- Simultaneous assignment
>> >
>> > I thought we rejected that idea once already, on the grounds that it
>> > would make it too hard to tell the difference between intended code
>> > and typos.
>> >
>>
>> In any case, I had some questions:
>>
>> . is it compatible with PLSQL?
>> . can the effect be achieved by assigning to a composite?
>
> I looked into SQL2003, and SQL2003 knows it (SQL/PSM):
>
> <assignment statement> ::=
> <singleton variable assignment>
> | <multiple variable assignment>
> <multiple variable assignment> ::=
> SET <assignment target list> <equals operator> <assigned row>
> <assignment target list> ::=
> <left paren> <assignment target> [ { <comma> <assignment target>
> }... ] <right paren>
> <singleton variable assignment> ::=
> SET <assignment target> <equals operator> <assignment source>
>

The parentheses are apparently required for multiple variables, so in
our case it might look like this:

(a,b,c) := foo(bar);

That might overcome the objection Tom referred to, I guess?

cheers

andrew


From: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: Pavel Stehule <pavel(dot)stehule(at)hotmail(dot)com>, tgl(at)sss(dot)pgh(dot)pa(dot)us, pgsql-hackers(at)postgresql(dot)org
Subject: Re: proposal for 8.3: Simultaneous assignment for PL/pgSQL
Date: 2006-08-08 15:35:59
Message-ID: 20060808153559.GB1647@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Andrew Dunstan wrote:
> Pavel Stehule wrote:

> >I looked into SQL2003, and SQL2003 knows it (SQL/PSM):
> > [grammar productions]
>
> The parentheses are apparently required for multiple variables, so in
> our case it might look like this:
>
> (a,b,c) := foo(bar);
>
> That might overcome the objection Tom referred to, I guess?

Are we intending to support SQL/PSM with PL/pgSQL?

--
Alvaro Herrera http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.


From: "Jonah H(dot) Harris" <jonah(dot)harris(at)gmail(dot)com>
To: "Andrew Dunstan" <andrew(at)dunslane(dot)net>, "Pavel Stehule" <pavel(dot)stehule(at)hotmail(dot)com>, tgl(at)sss(dot)pgh(dot)pa(dot)us, pgsql-hackers(at)postgresql(dot)org
Subject: Re: proposal for 8.3: Simultaneous assignment for PL/pgSQL
Date: 2006-08-08 15:40:40
Message-ID: 36e682920608080840x1aa431b1i2d4bd14c5db3db7d@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 8/8/06, Alvaro Herrera <alvherre(at)commandprompt(dot)com> wrote:
> Are we intending to support SQL/PSM with PL/pgSQL?

I hope not. While PL/pgSQL and SQL/PSM share some similarities, they
should be totally separate. IIRC, EnterpriseDB had tried to sponsor
someone to write SQL/PSM support for PostgreSQL a little over a year
ago and no one wanted to do it.

--
Jonah H. Harris, Software Architect | phone: 732.331.1300
EnterpriseDB Corporation | fax: 732.331.1301
33 Wood Ave S, 2nd Floor | jharris(at)enterprisedb(dot)com
Iselin, New Jersey 08830 | http://www.enterprisedb.com/


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: Pavel Stehule <pavel(dot)stehule(at)hotmail(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: proposal for 8.3: Simultaneous assignment for PL/pgSQL
Date: 2006-08-08 20:05:09
Message-ID: 12679.1155067509@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Andrew Dunstan <andrew(at)dunslane(dot)net> writes:
> Pavel Stehule wrote:
>> I looked into SQL2003, and SQL2003 knows it (SQL/PSM):
>>
>> <assignment statement> ::=
>> <singleton variable assignment>
>> | <multiple variable assignment>
>> <multiple variable assignment> ::=
>> SET <assignment target list> <equals operator> <assigned row>
>> <assignment target list> ::=
>> <left paren> <assignment target> [ { <comma> <assignment target>
>> }... ] <right paren>
>> <singleton variable assignment> ::=
>> SET <assignment target> <equals operator> <assignment source>

> The parentheses are apparently required for multiple variables, so in
> our case it might look like this:
> (a,b,c) := foo(bar);

More to the point, a SET keyword is required too by that standard.

I concur with the other comment that plpgql is intended to mimic
Oracle PL/SQL, not SQL/PSM. If we try to follow two different leads
we are likely to find ourselves with a mess.

regards, tom lane


From: Josh Berkus <josh(at)agliodbs(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Andrew Dunstan <andrew(at)dunslane(dot)net>, Pavel Stehule <pavel(dot)stehule(at)hotmail(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: proposal for 8.3: Simultaneous assignment for PL/pgSQL
Date: 2006-08-08 21:55:47
Message-ID: 44D90863.4010903@agliodbs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Tom,

> I concur with the other comment that plpgql is intended to mimic
> Oracle PL/SQL, not SQL/PSM. If we try to follow two different leads
> we are likely to find ourselves with a mess.

Well, the proposed functionality would be extremely useful in making
PL/pgSQL a more robust language. So can we find a syntax that is
unambiguously assignment? To be honest, I'm unclear on what's wrong
with Pavel's suggested syntax.

--Josh