Re: Find out the number of rows returned by refcursor?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Karen Hill" <karen_hill22(at)yahoo(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Find out the number of rows returned by refcursor?
Date: 2006-10-11 18:31:08
Message-ID: 28840.1160591468@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"Karen Hill" <karen_hill22(at)yahoo(dot)com> writes:
> -- Is there a way to know the total number of rows the cursor is
> capable of traversing without using --count?

If you want an accurate count, the only way is to traverse the cursor.
Consider using MOVE FORWARD ALL and noting the rowcount, then MOVE
BACKWARD ALL to reset the cursor (the latter at least should be
reasonably cheap).

If you can settle for a (potentially very inaccurate) estimate, consider
using EXPLAIN on the query and noting the planner's rowcount estimate.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Karen Hill 2006-10-11 18:42:09 Re: Find out the number of rows returned by refcursor?
Previous Message Uwe C. Schroeder 2006-10-11 18:05:48 Re: Is it possible to return custom type as proper ROW?