Re: number of rows in a cursor

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
Cc: Christoffer Gurell <orbit(at)0x63(dot)nu>, pgsql-general(at)postgresql(dot)org
Subject: Re: number of rows in a cursor
Date: 2004-02-10 15:34:06
Message-ID: 15013.1076427246@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> writes:
> Christoffer Gurell wrote:
>> After declaring a cursor. Is there any way you can check the number of rows
>> that cursor contains ??

> Yes, you can MOVE ALL in the cursor and look at the return status,

Note however that this is *not* a cheap operation. You might as well
fetch the data, because it's going to cost nearly as much as FETCH.

(Worse, in pre-7.4 versions, MOVE BACKWARDS ALL is also nearly as
expensive as FETCH, so that getting the number of rows and then fetching
the data will cost you close to 3x the runtime of the FETCH alone.)

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Richard Huxton 2004-02-10 15:38:27 Re: Strange Slow query
Previous Message Tom Lane 2004-02-10 15:21:36 Re: IP adrss and networks in Postgresql