Re: select from function

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Darren Ferguson <darren(at)crystalballinc(dot)com>
Cc: Anna Dorofiyenko <anna(dot)dorofiyenko(at)xdrive(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: select from function
Date: 2002-05-03 02:09:37
Message-ID: 2943.1020391777@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Darren Ferguson <darren(at)crystalballinc(dot)com> writes:
> So this leads me to believe that it is not supported this way

You forgot to open the cursor.

regression=# CREATE OR REPLACE FUNCTION test(integer,integer) RETURNS REFCURSOR AS '
regression'# DECLARE
regression'# test cursor for SELECT * from tenk1;
regression'# begin
regression'# open test;
regression'# RETURN test;
regression'# END;' LANGUAGE 'plpgsql';
CREATE
regression=# begin;
BEGIN
regression=# select test(4,5);
test
------
test
(1 row)

regression=# fetch forward 1 from test;
unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4
---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
8800 | 0 | 0 | 0 | 0 | 0 | 0 | 800 | 800 | 3800 | 8800 | 0 | 1 | MAAAAA | AAAAAA | AAAAxx
(1 row)

regression=#

I dunno why plpgsql is defined to need an OPEN for a cursor, but it is.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Thomas Lockhart 2002-05-03 02:20:56 Re: order of adding date & interval values?
Previous Message Darren Ferguson 2002-05-03 01:19:10 Re: order of adding date & interval values?