Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 8C60CB5DBC2 for ; Fri, 20 May 2011 17:16:15 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 18968-06 for ; Fri, 20 May 2011 20:16:03 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from spinlock.commandprompt.com (host-215.commandprompt.net [207.173.203.215]) by mail.postgresql.org (Postfix) with ESMTP id 79A9BB5DC0C for ; Fri, 20 May 2011 17:16:03 -0300 (ADT) Received: from localhost (localhost [127.0.0.1]) by spinlock.commandprompt.com (Postfix) with ESMTP id C2FAF348045; Fri, 20 May 2011 13:16:02 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at commandprompt.com Received: from spinlock.commandprompt.com ([127.0.0.1]) by localhost (spinlock.commandprompt.com.commandprompt.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id KHHwUYjVG4nD; Fri, 20 May 2011 13:16:01 -0700 (PDT) Received: from perhan.alvh.no-ip.org (unknown [200.85.213.137]) by spinlock.commandprompt.com (Postfix) with ESMTPSA id A80E6348044; Fri, 20 May 2011 13:16:00 -0700 (PDT) Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id 2D65D6E35C; Fri, 20 May 2011 16:15:58 -0400 (CLT) Content-Type: text/plain; charset=UTF-8 Cc: pgsql-bugs Subject: Re: BUG #6031: Bug with plpgsql function and RETURNS TABLE From: Alvaro Herrera To: Preston M. Price In-reply-to: <201105201612.p4KGC9Cx027071@wwwmaster.postgresql.org> References: <201105201612.p4KGC9Cx027071@wwwmaster.postgresql.org> Date: Fri, 20 May 2011 16:15:58 -0400 Message-Id: <1305922486-sup-532@alvh.no-ip.org> User-Agent: Sup/git Content-Transfer-Encoding: 8bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-5 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201105/145 X-Sequence-Number: 30284 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 The PostgreSQL Company - Command Prompt, Inc. PostgreSQL Replication, Consulting, Custom Development, 24x7 support