Strange bahaviour - Mailing list pgsql-hackers

From Michael Meskes
Subject Strange bahaviour
Date
Msg-id 20020812132603.GA32484@feivel.credativ.de
Whole thread Raw
Responses Re: Strange bahaviour  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
I just got the following example:

DROP TABLE foo;
CREATE TABLE foo (login varchar(100));
INSERT INTO foo values ('abc');

DROP FUNCTION footest1(varchar(100));
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';

DROP FUNCTION footest2(varchar(100));
CREATE FUNCTION footest2(varchar(100)) RETURNS varchar(100) AS '       DECLARE               fieldname varchar(100);
  BEGIN               SELECT INTO fieldname login FROM foo LIMIT 1;               RETURN fieldname;       END;
 
' LANGUAGE 'plpgsql';

SELECT footest1('foobar');
SELECT footest2('foobar');

The first select returns NULL while the second correctly returns 'abc'.
I just wonder why it is that way. The only difference seems to be the
name of the variable which in footest1 equals the attribute name. 

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

Michael
-- 
Michael Meskes
Michael@Fam-Meskes.De
Go SF 49ers! Go Rhein Fire!
Use Debian GNU/Linux! Use PostgreSQL!


pgsql-hackers by date:

Previous
From: Hannu Krosing
Date:
Subject: Re: OOP real life example (was Re: Why is MySQL more
Next
From: Greg Copeland
Date:
Subject: Re: [SECURITY] DoS attack on backend possible (was: Re: