pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Alvaro Herrera <alvherre@commandprompt.com>
To: Preston M. Price <preston@clearwateranalytics.com>
Cc: pgsql-bugs <pgsql-bugs@postgresql.org>
Subject: Re: BUG #6031: Bug with plpgsql function and RETURNS TABLE
Date: Fri, 20 May 2011 16:15:58 -0400
Message-ID: <1305922486-sup-532@alvh.no-ip.org> (raw)
In-Reply-To: <201105201612.p4KGC9Cx027071@wwwmaster.postgresql.org>
References: <201105201612.p4KGC9Cx027071@wwwmaster.postgresql.org>

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



view thread (2+ messages)

Message-ID: <1305922486-sup-532@alvh.no-ip.org>
Permalink:  ../1305922486-sup-532@alvh.no-ip.org/
Also on:    postgresql.org/message-id/1305922486-sup-532@alvh.no-ip.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: alvherre@commandprompt.com, preston@clearwateranalytics.com
  Subject: Re: BUG #6031: Bug with plpgsql function and RETURNS TABLE
  In-Reply-To: <1305922486-sup-532@alvh.no-ip.org>
  References: <201105201612.p4KGC9Cx027071@wwwmaster.postgresql.org> <1305922486-sup-532@alvh.no-ip.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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