Re: Strange bahaviour

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Michael Meskes <meskes(at)postgresql(dot)org>
Cc: PostgreSQL Hacker <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Strange bahaviour
Date: 2002-08-12 13:40:12
Message-ID: 4036.1029159612@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Michael Meskes <meskes(at)postgresql(dot)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 saying
login := 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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Florian Weimer 2002-08-12 13:48:10 Re: [SECURITY] DoS attack on backend possible (was: Re:
Previous Message Michael Meskes 2002-08-12 13:26:03 Strange bahaviour