Re: use cursor in a function - Mailing list pgsql-novice

From Rory Campbell-Lange
Subject Re: use cursor in a function
Date
Msg-id 20030617174449.GA8576@campbell-lange.net
Whole thread Raw
In response to Re: use cursor in a function  (Joe Conway <mail@joeconway.com>)
Responses Re: use cursor in a function
List pgsql-novice
In a nutshell:

Is there a way of finding out how many rows (ROW_COUNT) are in a cursor
select? If one can, is there a way of returning a RECORD containing the
refcursor and the ROW_COUNT?

So far I've only been able to get a clue from:

1) Define function
create or replace function mycur(refcursor) returns refcursor AS '
BEGIN
    open $1 for select * from abc;
    RETURN $1;
END;
' LANGUAGE 'plpgsql';

2) Call function
temporary=> select mycur('cur');
 mycur
-------
 cur
(1 row)

3) Try to find end of cursor
temporary=> move 99 from cur;
MOVE 5


On 17/06/03, Joe Conway (mail@joeconway.com) wrote:
> Rory Campbell-Lange wrote:
> >Is this sensible, efficient, feasible? I have not used cursors before.
> >
> >Or should I simply do 2 separate functions, 1 for NUM_ROWS, the
> >other for the result set I want?
>
> It's hard to offer advice (at least for me) without more context. What
> are you trying to accomplish (in more detail), and in what type of
> application (web, fat client, etc)?


--
Rory Campbell-Lange
<rory@campbell-lange.net>
<www.campbell-lange.net>

pgsql-novice by date:

Previous
From: Harry Broomhall
Date:
Subject: Re: Commit within a PL/PGSQL procedure
Next
From: Joe Conway
Date:
Subject: Re: use cursor in a function