Re: Strange bahaviour - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Strange bahaviour
Date
Msg-id 4036.1029159612@sss.pgh.pa.us
Whole thread Raw
In response to Strange bahaviour  (Michael Meskes <meskes@postgresql.org>)
Responses Re: Strange bahaviour  (Michael Meskes <meskes@postgresql.org>)
List pgsql-hackers
Michael Meskes <meskes@postgresql.org> writes:
> CREATE FUNCTION footest1(varchar(100)) RETURNS varchar(100) AS '
>         DECLARE
>                 login varchar(100);
>         BEGIN
>                 SELECT INTO login login FROM foo LIMIT 1;
>                 RETURN login;
>         END;
> ' LANGUAGE 'plpgsql';

> The first select returns NULL while the second correctly returns 'abc'.

The NULL is perfectly correct: that's the initial value of the plpgsql
variable.  The above is essentially the same as sayinglogin := login;
It is not "incorrect".

> Now I can guess what happens but I wonder if this is the desired
> behaviour.

Certainly, unless you'd like to disable all use of plpgsql variables in
SQL queries.  plpgsql has no way of guessing that "login" in the above
query wasn't intended to reference its variable.  Either choose a
different variable name, or qualify the query-variable reference
(eg, foo.login).
        regards, tom lane


pgsql-hackers by date:

Previous
From: Greg Copeland
Date:
Subject: Re: [SECURITY] DoS attack on backend possible (was: Re:
Next
From: Florian Weimer
Date:
Subject: Re: [SECURITY] DoS attack on backend possible (was: Re: