Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 47228B5DC35 for ; Fri, 20 May 2011 13:12:11 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 62928-04 for ; Fri, 20 May 2011 16:12:11 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from wwwmaster.postgresql.org (wwwmaster.postgresql.org [217.196.146.204]) by mail.postgresql.org (Postfix) with ESMTP id B8ACEB5DC34 for ; Fri, 20 May 2011 13:12:10 -0300 (ADT) Received: from wwwmaster.postgresql.org (wwwmaster.postgresql.org [217.196.146.204]) by wwwmaster.postgresql.org (8.14.3/8.14.3) with ESMTP id p4KGC9Vp027072 for ; Fri, 20 May 2011 16:12:09 GMT (envelope-from www@wwwmaster.postgresql.org) Received: (from www@localhost) by wwwmaster.postgresql.org (8.14.3/8.14.3/Submit) id p4KGC9Cx027071; Fri, 20 May 2011 16:12:09 GMT (envelope-from www) Date: Fri, 20 May 2011 16:12:09 GMT Message-Id: <201105201612.p4KGC9Cx027071@wwwmaster.postgresql.org> To: pgsql-bugs@postgresql.org Subject: BUG #6031: Bug with plpgsql function and RETURNS TABLE From: "Preston M. Price" Content-Type: text/plain; charset=utf-8 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 201105/144 X-Sequence-Number: 30283 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.