From: | "Eric B(dot) Ridge" <ebr(at)tcdi(dot)com> |
---|---|
To: | Cristian Prieto <cristian(at)clickdiario(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org, Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> |
Subject: | Re: Number of items in a cursor... |
Date: | 2005-11-15 18:11:03 |
Message-ID: | 80697F77-4512-405E-BAA2-B87A843DE11E@tcdi.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Nov 15, 2005, at 12:43 PM, Bruce Momjian wrote:
> Cristian Prieto wrote:
>> Is there any way to get the numbers of items inside a cursor?
>
> I can't see a way to do it except to do a FETCH ALL and count the
> returned rows.
What we do, via JDBC is:
MOVE <Integer.MAX_VALUE> IN cursor_name;
The JDBC drivers are nice enough to return the output message from
the MOVE command, which is the number of records moved. We just keep
doing this until it returns something less than <Integer.MAX_VALUE>.
The sum of all the moves is the total number of records. Then we
just "MOVE ABSOLUTE 0 in cursor_name;" to make use of the cursor
using FETCH.
While this does force the server to process the entire query it at
least avoids the overhead of returning all the records (which is the
point of cursors!).
eric
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2005-11-15 18:12:12 | Re: clustering by partial indexes |
Previous Message | Bob Pawley | 2005-11-15 18:10:15 | Re: Is it databases in general, SQL or Postgresql? |