Re: Reassign value of IN parameter in 9.1.1

From: Alban Hertroys <haramrae(at)gmail(dot)com>
To: Gavin Casey <gpjcasey(at)googlemail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Reassign value of IN parameter in 9.1.1
Date: 2011-11-24 14:12:13
Message-ID: CAF-3MvNNHuMFruT2vx=jkx1X+edc4nTcBkShXO3yEK4Od+R99g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 24 November 2011 14:52, Gavin Casey <gpjcasey(at)googlemail(dot)com> wrote:
> This works in 9.1.1 but seems like a bug to me:
>
> create function xout(_x INTEGER)
> returns integer
> as $$
> begin
>    _x = _x * 2;

I would expect an error here, as having an expression without a
context (an if-statement, for example) should be illegal.

An assignment should be fine though:
_x := _x * 2;

I'm guessing people make errors like this frequently enough that the
parser was relaxed to accept this expression as an assignment, even
though the syntax for those is slightly different. There is no other
possible explanation for such a line, after all, the author of this
code clearly meant to put an assignment there.

>    return _x;
> end;
> $$ LANGUAGE plpgsql;
>
> select xout(4);

What is the output? I'm guessing it's 8, since there was no syntax
error. That would be the right answer too, in that case.
Function-local variables don't matter outside the function, after all.
--
If you can't see the forest for the trees,
Cut the trees and you'll see there is no forest.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Gavin Casey 2011-11-24 14:19:34 Re: Reassign value of IN parameter in 9.1.1
Previous Message Tomas Vondra 2011-11-24 14:09:34 Re: General performance/load issue