pg.ddx.io pgsql-bugs@postgresql.org mailing list archivehelp / color / mirror / Atom feed
BUG #6031: Bug with plpgsql function and RETURNS TABLE 2+ messages / 2 participants [nested] [flat]
* BUG #6031: Bug with plpgsql function and RETURNS TABLE @ 2011-05-20 16:12 Preston M. Price <preston@clearwateranalytics.com> 0 siblings, 1 reply; 2+ messages in thread From: Preston M. Price @ 2011-05-20 16:12 UTC (permalink / raw) To: pgsql-bugs The following bug has been logged online: Bug reference: 6031 Logged by: Preston M. Price Email address: preston@clearwateranalytics.com PostgreSQL version: 8.4 Operating system: Linux (Ubuntu) Description: Bug with plpgsql function and RETURNS TABLE Details: If I create a plpgsql function and use RETURNS TABLE the returned result set is filled with null values rather than the values from the table. ---SETUP--- create table test ( ID SERIAL PRIMARY KEY, VAL INT NOT NULL ); INSERT INTO TEST(VAL) VALUES(1); INSERT INTO TEST(VAL) VALUES(2); INSERT INTO TEST(VAL) VALUES(3); INSERT INTO TEST(VAL) VALUES(4); INSERT INTO TEST(VAL) VALUES(5); CREATE FUNCTION TEST_FUNC() RETURNS TABLE(val int) AS $$ BEGIN RETURN QUERY SELECT VAL FROM test; END; $$ LANGUAGE plpgsql; ---SETUP--- select * from TEST_FUNC(); This query yields 5 rows of null rather than the values from the test table. ^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: BUG #6031: Bug with plpgsql function and RETURNS TABLE @ 2011-05-20 20:15 Alvaro Herrera <alvherre@commandprompt.com> parent: Preston M. Price <preston@clearwateranalytics.com> 0 siblings, 0 replies; 2+ messages in thread From: Alvaro Herrera @ 2011-05-20 20:15 UTC (permalink / raw) To: Preston M. Price <preston@clearwateranalytics.com>; +Cc: pgsql-bugs Excerpts from Preston M. Price's message of vie may 20 12:12:09 -0400 2011: > If I create a plpgsql function and use RETURNS TABLE > the returned result set is filled with null values rather than the values > from the table. > select * from TEST_FUNC(); > > This query yields 5 rows of null rather than the values from the test table. Yeah, known problem. Don't use the column name as variable name; or you can qualify the column name in the query, like this: alvherre=# CREATE or replace FUNCTION TEST_FUNC() RETURNS TABLE(val int) AS $$ BEGIN RETURN QUERY SELECT test.val FROM test; END; $$ LANGUAGE plpgsql; CREATE FUNCTION alvherre=# select * from TEST_FUNC(); val ----- 1 2 3 4 5 (5 filas) -- Álvaro Herrera <alvherre@commandprompt.com> The PostgreSQL Company - Command Prompt, Inc. PostgreSQL Replication, Consulting, Custom Development, 24x7 support ^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2011-05-20 20:15 UTC | newest] Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2011-05-20 16:12 BUG #6031: Bug with plpgsql function and RETURNS TABLE Preston M. Price <preston@clearwateranalytics.com> 2011-05-20 20:15 ` Alvaro Herrera <alvherre@commandprompt.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions for how to clone and mirror all data and code used for this inbox