Re: Passing refcursors between pl/pgsql functions

From: "Reuven M(dot) Lerner" <reuven(at)lerner(dot)co(dot)il>
To: Merlin Moncure <mmoncure(at)gmail(dot)com>
Cc: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: Passing refcursors between pl/pgsql functions
Date: 2010-10-14 04:31:17
Message-ID: 4CB68795.1050600@lerner.co.il
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi, Merlin. You wrote:

> In other words, something like this:
>
> create or replace function test() returns setof foo as
> $$
> declare
> r refcursor;
> f foo;
> i int;
> begin
> open r for select * from foo;
>
> for i in 1..10
> loop
> fetch 1 from r into f;
> exit when not found;
> return next f;
> end loop;
> end;
> $$ language plpgsql;
>
> Having defined refcursor separately from the place it is being used
> really had no bearing on the peculiarities of the 'fetch' statement.
This isn't quite what I was looking for; perhaps I didn't make myself clear.

I want to invoke one function, and get an open refcursor returned. That
much, I know how to do.

I then want to be able to call a second function, repeatedly, which will
essentially perform a "fetch 20" from that open refcursor. The second
function should have an input of a refcursor (already open), and should
return a set of rows from the table on which it was opened.

This isn't the way that I would want to do things, but my client's
application structure seems to require it, at least for now. So, is
there a way to do this?

Reuven

--
Reuven M. Lerner -- Web development, consulting, and training
Mobile: +972-54-496-8405 * US phone: 847-230-9795
Skype/AIM: reuvenlerner

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Vishnu S. 2010-10-14 05:39:57 PostgreSQL server not starting.
Previous Message Jayadevan M 2010-10-14 04:05:15 Re: How to search ignoring spaces and minus signs