PATCH: make plpgsql IN args mutable (v1)

Lists: pgsql-hackers
From: Steve Prentice <prentice(at)cisco(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: PATCH: make plpgsql IN args mutable (v1)
Date: 2009-07-30 20:37:16
Message-ID: BBE2C567-4995-4229-A811-0012FC263510@cisco.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Since I didn't get completely shot out of the water and a couple
people seemed to think it was helpful, I'm submitting this patch for
consideration in the next commitfest.

This patch changes plpgsql IN parameters so they are mutable.
Previously, they were being forced constant. This patch modifies the
plpgsql.sql regression test and corresponding .out file. The
regression test also makes sure the passed in parameter does not get
changed in the calling function.

I decided not to update the docs for this change because the docs
don't currently indicate that an IN parameter is constant and I didn't
want to encourage it because it isn't universally considered good
programming practice to assign to an IN parameter. If others think we
need a doc change for this, I'll update the patch.

The following function will compile with this patch:

create or replace function param_assign_test(a int, val int)
returns void as $$
begin
a := val;
end
$$ language plpgsql;

This function would have failed to compile previously.

-Steve

Attachment Content-Type Size
plpgsql_in_args_mutable-v1.diff application/octet-stream 2.0 KB

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Steve Prentice <prentice(at)cisco(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: PATCH: make plpgsql IN args mutable (v1)
Date: 2009-07-30 21:06:17
Message-ID: 603c8f070907301406h589d1f94p33e70cbd7a6b6e2a@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, Jul 30, 2009 at 4:37 PM, Steve Prentice<prentice(at)cisco(dot)com> wrote:
> Since I didn't get completely shot out of the water and a couple people
> seemed to think it was helpful, I'm submitting this patch for consideration
> in the next commitfest.
>
> This patch changes plpgsql IN parameters so they are mutable. Previously,
> they were being forced constant. This patch modifies the plpgsql.sql
> regression test and corresponding .out file. The regression test also makes
> sure the passed in parameter does not get changed in the calling function.
>
> I decided not to update the docs for this change because the docs don't
> currently indicate that an IN parameter is constant and I didn't want to
> encourage it because it isn't universally considered good programming
> practice to assign to an IN parameter. If others think we need a doc change
> for this, I'll update the patch.
>
> The following function will compile with this patch:
>
>  create or replace function param_assign_test(a int, val int) returns void
> as $$
>  begin
>    a := val;
>  end
>  $$ language plpgsql;
>
> This function would have failed to compile previously.

We're in the middle of a CommitFest right now for which the deadline
for submissions was 2009-07-14. Please go to
https://commitfest.postgresql.org/action/commitfest_view/open and add
your patch there.

Thanks,

...Robert


From: David Fetter <david(at)fetter(dot)org>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Steve Prentice <prentice(at)cisco(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: PATCH: make plpgsql IN args mutable (v1)
Date: 2009-07-31 00:40:58
Message-ID: 20090731004058.GB28990@fetter.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, Jul 30, 2009 at 05:06:17PM -0400, Robert Haas wrote:
> On Thu, Jul 30, 2009 at 4:37 PM, Steve Prentice<prentice(at)cisco(dot)com> wrote:
> > Since I didn't get completely shot out of the water and a couple people
> > seemed to think it was helpful, I'm submitting this patch for consideration
> > in the next commitfest.
> >
> > This patch changes plpgsql IN parameters so they are mutable. Previously,
> > they were being forced constant. This patch modifies the plpgsql.sql
> > regression test and corresponding .out file. The regression test also makes
> > sure the passed in parameter does not get changed in the calling function.

Wouldn't INOUT parameters cover this case?

Cheers,
David.
--
David Fetter <david(at)fetter(dot)org> http://fetter.org/
Phone: +1 415 235 3778 AIM: dfetter666 Yahoo!: dfetter
Skype: davidfetter XMPP: david(dot)fetter(at)gmail(dot)com

Remember to vote!
Consider donating to Postgres: http://www.postgresql.org/about/donate


From: Jeff Davis <pgsql(at)j-davis(dot)com>
To: David Fetter <david(at)fetter(dot)org>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Steve Prentice <prentice(at)cisco(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: PATCH: make plpgsql IN args mutable (v1)
Date: 2009-07-31 01:39:24
Message-ID: 1249004364.709.3.camel@monkey-cat.sm.truviso.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, 2009-07-30 at 17:40 -0700, David Fetter wrote:
> > > This patch changes plpgsql IN parameters so they are mutable. Previously,
> > > they were being forced constant. This patch modifies the plpgsql.sql
> > > regression test and corresponding .out file. The regression test also makes
> > > sure the passed in parameter does not get changed in the calling function.
>
> Wouldn't INOUT parameters cover this case?

That was my first, thought, but I don't think it solves his concern. The
out parameters are returned as part of a record, but he actually wants
to mutate the value passed in.

If mutable IN parameters were allowed, I don't even think it could be
allowable to call them from the SQL level, you could only from another
function.

For instance, what would it mean if you did something like:

SELECT foo(a) FROM mytable;

Where foo() mutated it's IN argument? Would that really be an UPDATE?

Regards,
Jeff Davis


From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Jeff Davis <pgsql(at)j-davis(dot)com>
Cc: David Fetter <david(at)fetter(dot)org>, Robert Haas <robertmhaas(at)gmail(dot)com>, Steve Prentice <prentice(at)cisco(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: PATCH: make plpgsql IN args mutable (v1)
Date: 2009-07-31 01:45:36
Message-ID: 4A724CC0.50208@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Jeff Davis wrote:
> If mutable IN parameters were allowed, I don't even think it could be
> allowable to call them from the SQL level, you could only from another
> function.
>
> For instance, what would it mean if you did something like:
>
> SELECT foo(a) FROM mytable;
>
> Where foo() mutated it's IN argument? Would that really be an UPDATE?
>
>
>

No, surely the mutated value will only be visible within the scope of
the function, i.e. it will be a purely local copy that gets altered.

cheers

andrew


From: Jeff Davis <pgsql(at)j-davis(dot)com>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: David Fetter <david(at)fetter(dot)org>, Robert Haas <robertmhaas(at)gmail(dot)com>, Steve Prentice <prentice(at)cisco(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: PATCH: make plpgsql IN args mutable (v1)
Date: 2009-07-31 04:59:10
Message-ID: 1249016350.4765.3073.camel@jdavis
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, 2009-07-30 at 21:45 -0400, Andrew Dunstan wrote:
> > For instance, what would it mean if y
> > SELECT foo(a) FROM mytable;
> >
> > Where foo() mutated it's IN argument? Would that really be an UPDATE?
> >
> No, surely the mutated value will only be visible within the scope of
> the function, i.e. it will be a purely local copy that gets altered.

Oh, I misunderstood the example here:

http://archives.postgresql.org/pgsql-hackers/2009-07/msg01931.php

I thought he was saying that the PERFORM in test1() _should_ have
mutated "a", when in fact, he was trying to demonstrate that it does not
(with his patch or without).

Regards,
Jeff Davis


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Steve Prentice <prentice(at)cisco(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: PATCH: make plpgsql IN args mutable (v1)
Date: 2009-07-31 06:57:39
Message-ID: 162867790907302357y2e27bb3bsb278ad51221d55dd@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

2009/7/30 Steve Prentice <prentice(at)cisco(dot)com>:
> Since I didn't get completely shot out of the water and a couple people
> seemed to think it was helpful, I'm submitting this patch for consideration
> in the next commitfest.
>
> This patch changes plpgsql IN parameters so they are mutable. Previously,
> they were being forced constant. This patch modifies the plpgsql.sql
> regression test and corresponding .out file. The regression test also makes
> sure the passed in parameter does not get changed in the calling function.
>
> I decided not to update the docs for this change because the docs don't
> currently indicate that an IN parameter is constant and I didn't want to
> encourage it because it isn't universally considered good programming
> practice to assign to an IN parameter. If others think we need a doc change
> for this, I'll update the patch.
>
> The following function will compile with this patch:
>
>  create or replace function param_assign_test(a int, val int) returns void
> as $$
>  begin
>    a := val;
>  end
>  $$ language plpgsql;
>

This behave is in conflict with PL/SQL, what should do some problems.
I thing, so I understand well, why this behave is in PL/SQL. It hasn't
sense in plpgsql, because OUT and INOUT params has little bit
different syntax (calling) and nobody will do similar bugs (perhaps).
What is interesting - this behave is in conformity with SQL/PSM, where
parameters are mutable too.

I am for it. PL/pgSQL doesn't promise compatibility with PL/SQL and
this change should to help some beginners (and this limit is
artificial and unnecessary).

Regards
Pavel Stehule

> This function would have failed to compile previously.
>
> -Steve
>
>
>
>
>
> --
> Sent via pgsql-hackers mailing list (pgsql-hackers(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-hackers
>
>


From: Abhijit Menon-Sen <ams(at)toroid(dot)org>
To: pgsql-hackers(at)postgresql(dot)org
Cc: Steve Prentice <prentice(at)cisco(dot)com>
Subject: Re: PATCH: make plpgsql IN args mutable (v1) [REVIEW]
Date: 2009-09-16 06:45:16
Message-ID: 20090916064516.GA10198@toroid.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

At 2009-07-30 13:37:16 -0700, prentice(at)cisco(dot)com wrote:
>
> This patch changes plpgsql IN parameters so they are mutable.

Makes sense, applies fine, works fine.

-- ams


From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Abhijit Menon-Sen <ams(at)toroid(dot)org>
Cc: pgsql-hackers(at)postgresql(dot)org, Steve Prentice <prentice(at)cisco(dot)com>
Subject: Re: PATCH: make plpgsql IN args mutable (v1) [REVIEW]
Date: 2009-09-16 12:37:40
Message-ID: 4AB0DC14.3000303@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Abhijit Menon-Sen wrote:
> At 2009-07-30 13:37:16 -0700, prentice(at)cisco(dot)com wrote:
>
>> This patch changes plpgsql IN parameters so they are mutable.
>>
>
> Makes sense, applies fine, works fine.
>
>
>

How does this compare with PLSQL? I know in Ada an IN argument is in
effect a constant. I understand the utility, because I occasionally
knock against this restriction, but if it's incompatible with PLSQL I
think we should think about it more carefully.

cheers

andrew


From: Abhijit Menon-Sen <ams(at)toroid(dot)org>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: pgsql-hackers(at)postgresql(dot)org, Steve Prentice <prentice(at)cisco(dot)com>
Subject: Re: PATCH: make plpgsql IN args mutable (v1) [REVIEW]
Date: 2009-09-16 12:46:59
Message-ID: 20090916124659.GA1797@toroid.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

At 2009-09-16 08:37:40 -0400, andrew(at)dunslane(dot)net wrote:
>
> How does this compare with PLSQL?

I don't remember anything of PL/SQL myself, but Pavel Stehule had this
to say in response to the original post:

> This behave is in conflict with PL/SQL, what should do some problems.
> I thing, so I understand well, why this behave is in PL/SQL. It hasn't
> sense in plpgsql, because OUT and INOUT params has little bit
> different syntax (calling) and nobody will do similar bugs (perhaps).
> What is interesting - this behave is in conformity with SQL/PSM, where
> parameters are mutable too.
>
> I am for it. PL/pgSQL doesn't promise compatibility with PL/SQL and
> this change should to help some beginners (and this limit is
> artificial and unnecessary).

Given the existing OUT/INOUT syntax difference as noted, I don't think
the patch represents a significant problem.

-- ams


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: Abhijit Menon-Sen <ams(at)toroid(dot)org>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>, Steve Prentice <prentice(at)cisco(dot)com>
Subject: Re: PATCH: make plpgsql IN args mutable (v1) [REVIEW]
Date: 2009-09-16 12:59:36
Message-ID: 5173F567-0B5D-4B6A-90A0-3242B070486D@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Sep 16, 2009, at 8:37 AM, Andrew Dunstan <andrew(at)dunslane(dot)net> wrote:

>
>
> Abhijit Menon-Sen wrote:
>> At 2009-07-30 13:37:16 -0700, prentice(at)cisco(dot)com wrote:
>>
>>> This patch changes plpgsql IN parameters so they are mutable.
>>>
>>
>> Makes sense, applies fine, works fine.
>>
>>
>>
>
> How does this compare with PLSQL? I know in Ada an IN argument is in
> effect a constant. I understand the utility, because I occasionally
> knock against this restriction, but if it's incompatible with PLSQL
> I think we should think about it more carefully.

At worst it's an upward-compatible extension, or am I wrong? If it's
useful, which I think it is, what's the harm?

...Robert


From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Abhijit Menon-Sen <ams(at)toroid(dot)org>
Cc: pgsql-hackers(at)postgresql(dot)org, Steve Prentice <prentice(at)cisco(dot)com>
Subject: Re: PATCH: make plpgsql IN args mutable (v1) [REVIEW]
Date: 2009-09-16 13:03:27
Message-ID: 4AB0E21F.2070908@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Abhijit Menon-Sen wrote:
> At 2009-09-16 08:37:40 -0400, andrew(at)dunslane(dot)net wrote:
>
>> How does this compare with PLSQL?
>>
>
> I don't remember anything of PL/SQL myself, but Pavel Stehule had this
> to say in response to the original post:
>
>
>> This behave is in conflict with PL/SQL, what should do some problems.
>> I thing, so I understand well, why this behave is in PL/SQL. It hasn't
>> sense in plpgsql, because OUT and INOUT params has little bit
>> different syntax (calling) and nobody will do similar bugs (perhaps).
>> What is interesting - this behave is in conformity with SQL/PSM, where
>> parameters are mutable too.
>>
>> I am for it. PL/pgSQL doesn't promise compatibility with PL/SQL and
>> this change should to help some beginners (and this limit is
>> artificial and unnecessary).
>>
>
> Given the existing OUT/INOUT syntax difference as noted, I don't think
> the patch represents a significant problem.
>
>
>

I'm not terribly impressed by either of Pavel's arguments. SQL/PSM is
irrelevant, and the existence of one inconsistency doesn't seems to me
to be a good rationale to create another. If there were a major increase
in utility I would be more willing, but at best this overcomes a minor
inconvenience, that is easily worked around.

It probably won't cause any problem with code being migrated from PLSQL,
but it will affect code going the other way. The question is: do we care
about that? I'm prepared to be persuaded that we shouldn't care, but I'm
not quite there yet.

cheers

andrew


From: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: Abhijit Menon-Sen <ams(at)toroid(dot)org>, pgsql-hackers(at)postgresql(dot)org, Steve Prentice <prentice(at)cisco(dot)com>
Subject: Re: PATCH: make plpgsql IN args mutable (v1) [REVIEW]
Date: 2009-09-16 13:59:46
Message-ID: 20090916135946.GF13076@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Andrew Dunstan wrote:

> It probably won't cause any problem with code being migrated from
> PLSQL, but it will affect code going the other way. The question is:
> do we care about that? I'm prepared to be persuaded that we
> shouldn't care, but I'm not quite there yet.

Anybody trying to port code from PL/pgSQL to PL/SQL is going to be a lot
more inconvenienced by the OUT parameter stuff.

--
Alvaro Herrera http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: Abhijit Menon-Sen <ams(at)toroid(dot)org>, pgsql-hackers(at)postgresql(dot)org, Steve Prentice <prentice(at)cisco(dot)com>
Subject: Re: PATCH: make plpgsql IN args mutable (v1) [REVIEW]
Date: 2009-09-16 14:07:09
Message-ID: 4136.1253110029@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Andrew Dunstan <andrew(at)dunslane(dot)net> writes:
> It probably won't cause any problem with code being migrated from PLSQL,
> but it will affect code going the other way. The question is: do we care
> about that? I'm prepared to be persuaded that we shouldn't care, but I'm
> not quite there yet.

IIRC the original complaint was from someone trying to migrate code
from T/SQL or some other not-quite-PLSQL language. Like you, I'm on
the fence about whether to accept this patch, but it does have some
in-migration rationale.

regards, tom lane


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: Abhijit Menon-Sen <ams(at)toroid(dot)org>, pgsql-hackers(at)postgresql(dot)org, Steve Prentice <prentice(at)cisco(dot)com>
Subject: Re: PATCH: make plpgsql IN args mutable (v1) [REVIEW]
Date: 2009-09-16 14:17:20
Message-ID: 162867790909160717x2e48d86fxb26d255bd3908a76@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

>>
>
> I'm not terribly impressed by either of Pavel's arguments. SQL/PSM is
> irrelevant, and the existence of one inconsistency doesn't seems to me to be
> a good rationale to create another. If there were a major increase in
> utility I would be more willing, but at best this overcomes a minor
> inconvenience, that is easily worked around.
>
> It probably won't cause any problem with code being migrated from PLSQL, but
> it will affect code going the other way. The question is: do we care about
> that? I'm prepared to be persuaded that we shouldn't care, but I'm not quite
> there yet.
>

In this case I have not strong opinion. Similarity with SQL/PSM isn't
my main argument. I see, so immutable IN arguments are typical problem
for beginners. Internally arguments are not immutable - so mutable
arguments should help to people who start with PostgreSQL.

But I accept, so this increase difference between plpgsql and pl/sql
what is wrong too.

Regards
Pavel

> cheers
>
> andrew
>
> --
> Sent via pgsql-hackers mailing list (pgsql-hackers(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-hackers
>


From: Steve Prentice <prentice(at)cisco(dot)com>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: Abhijit Menon-Sen <ams(at)toroid(dot)org>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: PATCH: make plpgsql IN args mutable (v1) [REVIEW]
Date: 2009-09-16 14:19:25
Message-ID: DD0FE1BA-CA3A-473F-A3FE-67244F6B3ABC@cisco.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Sep 16, 2009, at 6:03 AM, Andrew Dunstan wrote:
> Abhijit Menon-Sen wrote:
>> At 2009-09-16 08:37:40 -0400, andrew(at)dunslane(dot)net wrote:
>>> How does this compare with PLSQL?
>>
>> I don't remember anything of PL/SQL myself, but Pavel Stehule had
>> this
>> to say in response to the original post:
>>
>>> This behave is in conflict with PL/SQL, what should do some
>>> problems.
>>> I thing, so I understand well, why this behave is in PL/SQL. It
>>> hasn't
>>> sense in plpgsql, because OUT and INOUT params has little bit
>>> different syntax (calling) and nobody will do similar bugs
>>> (perhaps).
>>> What is interesting - this behave is in conformity with SQL/PSM,
>>> where
>>> parameters are mutable too.
>>>
>>> I am for it. PL/pgSQL doesn't promise compatibility with PL/SQL and
>>> this change should to help some beginners (and this limit is
>>> artificial and unnecessary).
>>
>> Given the existing OUT/INOUT syntax difference as noted, I don't
>> think
>> the patch represents a significant problem.
>
> I'm not terribly impressed by either of Pavel's arguments. SQL/PSM
> is irrelevant, and the existence of one inconsistency doesn't seems
> to me to be a good rationale to create another. If there were a
> major increase in utility I would be more willing, but at best this
> overcomes a minor inconvenience, that is easily worked around.
>
> It probably won't cause any problem with code being migrated from
> PLSQL, but it will affect code going the other way. The question is:
> do we care about that? I'm prepared to be persuaded that we
> shouldn't care, but I'm not quite there yet.

My motivation for submitting the patch was that it makes porting a
huge collection of Informix SPL stored procedures easier. There are so
many differences between plpgsql and SPL that you would think this
wasn't that big of a deal, however, most of the other issues are
easily taken care of with a simple sed script or something slightly
more advanced (e.g. dealing with the declare/define block
differences). This is one of the few compatibility issues where you
really need to review and change lots of code by hand.

The patch doesn't break existing code and doesn't make it any harder
to port code from PL/SQL and on the flip side, this patch with the
named/mixed notation patch from Pavel makes porting from Informix's
SPL much easier.

Thanks for everyone's consideration.

-Steve


From: Merlin Moncure <mmoncure(at)gmail(dot)com>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Andrew Dunstan <andrew(at)dunslane(dot)net>, Abhijit Menon-Sen <ams(at)toroid(dot)org>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>, Steve Prentice <prentice(at)cisco(dot)com>
Subject: Re: PATCH: make plpgsql IN args mutable (v1) [REVIEW]
Date: 2009-09-16 15:49:45
Message-ID: b42b73150909160849y678f5a79w76520d9053f1b20a@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Wed, Sep 16, 2009 at 8:59 AM, Robert Haas <robertmhaas(at)gmail(dot)com> wrote:
> On Sep 16, 2009, at 8:37 AM, Andrew Dunstan <andrew(at)dunslane(dot)net> wrote:
>
>>
>>
>> Abhijit Menon-Sen wrote:
>>>
>>> At 2009-07-30 13:37:16 -0700, prentice(at)cisco(dot)com wrote:
>>>
>>>> This patch changes plpgsql IN parameters so they are mutable.
>>>>
>>>
>>> Makes sense, applies fine, works fine.
>>>
>>>
>>>
>>
>> How does this compare with PLSQL? I know in Ada an IN argument is in
>> effect a constant. I understand the utility, because I occasionally knock
>> against this restriction, but if it's incompatible with PLSQL I think we
>> should think about it more carefully.
>
> At worst it's an upward-compatible extension, or am I wrong?  If it's
> useful, which I think it is, what's the harm?

are we guarding against cases like:
select _foo, adjust_foo(_foo) from bar; -- adjust_foo is inout

??
merlin


From: Steve Prentice <prentice(at)cisco(dot)com>
To: Merlin Moncure <mmoncure(at)gmail(dot)com>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Abhijit Menon-Sen <ams(at)toroid(dot)org>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: PATCH: make plpgsql IN args mutable (v1) [REVIEW]
Date: 2009-09-16 16:19:25
Message-ID: C1A58669-30CE-453F-A3B1-9833BE44A4BC@cisco.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Sep 16, 2009, at 8:49 AM, Merlin Moncure wrote:
> On Wed, Sep 16, 2009 at 8:59 AM, Robert Haas <robertmhaas(at)gmail(dot)com>
> wrote:
>> At worst it's an upward-compatible extension, or am I wrong? If it's
>> useful, which I think it is, what's the harm?
>
> are we guarding against cases like:
> select _foo, adjust_foo(_foo) from bar; -- adjust_foo is inout

Two things:

1) the patch only affects IN parameters,

2) the parameter is a local copy and doesn't affect parameters/
variables outside of its scope.


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>, Abhijit Menon-Sen <ams(at)toroid(dot)org>, pgsql-hackers(at)postgresql(dot)org, Steve Prentice <prentice(at)cisco(dot)com>
Subject: Re: PATCH: make plpgsql IN args mutable (v1) [REVIEW]
Date: 2009-09-16 17:40:54
Message-ID: 4AB12326.5080109@agliodbs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


> IIRC the original complaint was from someone trying to migrate code
> from T/SQL or some other not-quite-PLSQL language. Like you, I'm on
> the fence about whether to accept this patch, but it does have some
> in-migration rationale.

As someone who writes a lot of plpgsql, I'm in favor of the patch.

1. Compatibility with PL/SQL, especially in the extra features
direction, has never been a tremendous priority for us before;

2. We don't particularly care if native plpgsql procedures can be
back-ported to PLSQL, and if we did there are much greater compatibility
issues than this one;

3. This patch eliminates a common plpgsql beginner error and saves all
of us heavy plpgsql users some typing, especially when the use of a
mutable variable means that we can eliminate the DECLARE section
entirely, as in:

This:

CREATE PROCEDURE mod ( x int, y int )
RETURNS int LANGUAGE plpgsql
AS $f$
DECLARE
z INT := x;
BEGIN
z := x % y;
RETURN z;
END; $f$

Becomes this:

CREATE PROCEDURE mod ( x int, y int )
RETURNS int LANGUAGE plpgsql
AS $f$
BEGIN
x := x % y;
RETURN x;
END; $f$

--
Josh Berkus
PostgreSQL Experts Inc.
www.pgexperts.com


From: Michael Glaesemann <grzm(at)seespotcode(dot)net>
To: Josh Berkus <josh(at)agliodbs(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Abhijit Menon-Sen <ams(at)toroid(dot)org>, pgsql-hackers(at)postgresql(dot)org, Steve Prentice <prentice(at)cisco(dot)com>
Subject: Re: PATCH: make plpgsql IN args mutable (v1) [REVIEW]
Date: 2009-09-16 18:34:17
Message-ID: 373468D7-CB78-4D51-AA82-5323D848FA71@seespotcode.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


On Sep 16, 2009, at 13:40 , Josh Berkus wrote:

> 3. This patch eliminates a common plpgsql beginner error and saves all
> of us heavy plpgsql users some typing, especially when the use of a
> mutable variable means that we can eliminate the DECLARE section
> entirely, as in:
>
> This:
>
> CREATE PROCEDURE mod ( x int, y int )
> RETURNS int LANGUAGE plpgsql
> AS $f$
> DECLARE
> z INT := x;
> BEGIN
> z := x % y;
> RETURN z;
> END; $f$

This is also currently valid:

CREATE FUNCTION mod (x int, y int)
RETURNS int LANGUAGE plpgsql
AS $f$
DECLARE
z INT := x % y;
BEGIN
RETURN z;
END; $f$

As is this:

CREATE FUNCTION mod (x int, y int)
RETURNS int LANGUAGE plpgsql
AS $f$
BEGIN
RETURN (x % y);
END; $f$

Michael Glaesemann
grzm seespotcode net


From: Josh Berkus <josh(at)agliodbs(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: PATCH: make plpgsql IN args mutable (v1) [REVIEW]
Date: 2009-09-16 19:17:08
Message-ID: 4AB139B4.9060004@agliodbs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Michael,

> This is also currently valid:
>
> CREATE FUNCTION mod (x int, y int)
> RETURNS int LANGUAGE plpgsql
> AS $f$
> DECLARE
> z INT := x % y;
> BEGIN
> RETURN z;
> END; $f$
>
> As is this:
>
> CREATE FUNCTION mod (x int, y int)
> RETURNS int LANGUAGE plpgsql
> AS $f$
> BEGIN
> RETURN (x % y);
> END; $f$

Certainly. I was doing that to have a simple example; obviously you
wouldn't write a mod funciton, and you wouldn't do it in plpgsql. There
are other case where the lack of mutability in IN parameters causes you
to create a throwaway variable.

--
Josh Berkus
PostgreSQL Experts Inc.
www.pgexperts.com


From: Michael Glaesemann <grzm(at)seespotcode(dot)net>
To: Josh Berkus <josh(at)agliodbs(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: PATCH: make plpgsql IN args mutable (v1) [REVIEW]
Date: 2009-09-16 19:44:04
Message-ID: CC6E3E20-28B2-450A-A539-E4486D1F4689@seespotcode.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


On Sep 16, 2009, at 15:17 , Josh Berkus wrote:

> Michael,
>
>> This is also currently valid:
>>
>> CREATE FUNCTION mod (x int, y int)
>> RETURNS int LANGUAGE plpgsql
>> AS $f$
>> DECLARE
>> z INT := x % y;
>> BEGIN
>> RETURN z;
>> END; $f$
>>
>> As is this:
>>
>> CREATE FUNCTION mod (x int, y int)
>> RETURNS int LANGUAGE plpgsql
>> AS $f$
>> BEGIN
>> RETURN (x % y);
>> END; $f$
>
> Certainly. I was doing that to have a simple example; obviously you
> wouldn't write a mod funciton, and you wouldn't do it in plpgsql.
> There
> are other case where the lack of mutability in IN parameters causes
> you
> to create a throwaway variable.

Have an example at hand? I'd argue that in a case of a function of
more complexity from a code clarity standpoint you'd want to assign to
a new variable that describes what the new value reflects.

Michael Glaesemann
grzm seespotcode net


From: Steve Prentice <prentice(at)cisco(dot)com>
To: Michael Glaesemann <grzm(at)seespotcode(dot)net>
Cc: Josh Berkus <josh(at)agliodbs(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: PATCH: make plpgsql IN args mutable (v1) [REVIEW]
Date: 2009-09-16 20:16:21
Message-ID: 42C79B2E-5796-4237-B274-A327F43C1F04@cisco.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

> On Sep 16, 2009, at 12:44 PM, Michael Glaesemann wrote:
>
>> Certainly. I was doing that to have a simple example; obviously you
>> wouldn't write a mod funciton, and you wouldn't do it in plpgsql.
>> There
>> are other case where the lack of mutability in IN parameters causes
>> you
>> to create a throwaway variable.
>
> Have an example at hand? I'd argue that in a case of a function of
> more complexity from a code clarity standpoint you'd want to assign
> to a new variable that describes what the new value reflects.

I can't say I disagree with you from a purist standpoint, but for
porting existing code sometimes it's more efficient to port what you
have without rewriting it. In some of the code I'm looking at porting,
this is a very simple example of a common pattern I'm seeing:

create function create_some_object(pobjectid uuid, psomefkobjectid
uuid) returns uuid as $$
begin
if pobjectid is null then
pobjectid := newid()
end if

if psomefkobjectid is null then
select objectid into psomefkobjectid from somefktable where whatever;
end if

-- create the object
return pobjectid
end;

-Steve


From: Josh Berkus <josh(at)agliodbs(dot)com>
To: Michael Glaesemann <grzm(at)seespotcode(dot)net>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: PATCH: make plpgsql IN args mutable (v1) [REVIEW]
Date: 2009-09-16 21:31:16
Message-ID: 4AB15924.7040007@agliodbs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Michael,

> Have an example at hand? I'd argue that in a case of a function of more
> complexity from a code clarity standpoint you'd want to assign to a new
> variable that describes what the new value reflects.

Depends on what programming language you're used to. For those of us
who do a lot of pass-by-reference in our non-database code, reusing the
IN variable is "natural". I know not being able to is a longstanding
annoyance for me.

And I really don't think it's the place of the PostgreSQL project to try
to force what some of us think is good PL coding style on people.

--
Josh Berkus
PostgreSQL Experts Inc.
www.pgexperts.com


From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Josh Berkus <josh(at)agliodbs(dot)com>
Cc: Michael Glaesemann <grzm(at)seespotcode(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: PATCH: make plpgsql IN args mutable (v1) [REVIEW]
Date: 2009-09-16 21:44:58
Message-ID: 4AB15C5A.4040305@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Josh Berkus wrote:
> Michael,
>
>
>> Have an example at hand? I'd argue that in a case of a function of more
>> complexity from a code clarity standpoint you'd want to assign to a new
>> variable that describes what the new value reflects.
>>
>
> Depends on what programming language you're used to. For those of us
> who do a lot of pass-by-reference in our non-database code, reusing the
> IN variable is "natural". I know not being able to is a longstanding
> annoyance for me.
>
>
>

It's the pass by reference case that would be dangerous, in fact. The
fact that in C all function parameters are passed by value (unlike, say,
FORTRAN) is what makes it safe to modify them inside the function.

Anyway, debates about such thigs tend to get a bit religious. getting
more practical, I'm slightly inclined to say Steve Prentice has made a
good enough case for doing this.

cheers

andrew


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Josh Berkus <josh(at)agliodbs(dot)com>
Cc: Andrew Dunstan <andrew(at)dunslane(dot)net>, Abhijit Menon-Sen <ams(at)toroid(dot)org>, pgsql-hackers(at)postgresql(dot)org, Steve Prentice <prentice(at)cisco(dot)com>
Subject: Re: PATCH: make plpgsql IN args mutable (v1) [REVIEW]
Date: 2009-09-17 00:08:18
Message-ID: 3148.1253146098@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Josh Berkus <josh(at)agliodbs(dot)com> writes:
> 3. This patch eliminates a common plpgsql beginner error

With respect, that argument is one hundred percent false. I can think
of maybe two complaints about the behavior that we've heard in the last
ten years.

The only real argument I've heard in favor of this is that it will
simplify importing not-too-well-written Informix code. That might be
sufficient reason, but let's not invent claims about it being a common
problem.

regards, tom lane


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Steve Prentice <prentice(at)cisco(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: PATCH: make plpgsql IN args mutable (v1)
Date: 2009-09-20 01:55:04
Message-ID: 14491.1253411704@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Steve Prentice <prentice(at)cisco(dot)com> writes:
> This patch changes plpgsql IN parameters so they are mutable.

I've applied this, since the consensus seemed to be in favor of it.

> I decided not to update the docs for this change because the docs
> don't currently indicate that an IN parameter is constant and I didn't
> want to encourage it because it isn't universally considered good
> programming practice to assign to an IN parameter. If others think we
> need a doc change for this, I'll update the patch.

I agree, no need to say anything one way or the other in the plpgsql docs.
We'll want to mention it in the release notes of course.

regards, tom lane


From: Steve Prentice <prentice(at)cisco(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: PATCH: make plpgsql IN args mutable (v1)
Date: 2009-09-21 04:01:36
Message-ID: AD33A76E-B369-4FC5-BE61-1E8D347383AC@cisco.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Thank you!

-Steve

On Sep 19, 2009, at 6:55 PM, Tom Lane wrote:

Steve Prentice <prentice(at)cisco(dot)com> writes:
> This patch changes plpgsql IN parameters so they are mutable.

I've applied this, since the consensus seemed to be in favor of it.

> I decided not to update the docs for this change because the docs
> don't currently indicate that an IN parameter is constant and I didn't
> want to encourage it because it isn't universally considered good
> programming practice to assign to an IN parameter. If others think we
> need a doc change for this, I'll update the patch.

I agree, no need to say anything one way or the other in the plpgsql
docs.
We'll want to mention it in the release notes of course.

regards, tom lane