From: Knut P. Lehre <k.p.d.lehre@basalmed.uio.no>
To: pgsql-sql@postgresql.org, Christoph Haller <ch@rodos.fzk.de>
Subject: Re: length of recordset read through a cursor
Date: Tue, 05 Aug 2003 13:13:00 +0200
Message-ID: <5.2.0.9.2.20030805123048.01415ed8@uio-pop.uio.no> (raw)
>> After declaring a cursor, one way of obtaining the length of the
>resultset
>> is to perform a "MOVE 0" and read the PQcmdStatus which returns a
>"MOVE nn"
>> where nn is the length of the resultset. (A negative MOVE can then be
>used
>> to allow starting to fetch records from the beginning of the
>resultset.)
>>
>> Is there another, possibly faster way?
>>
>Looks like you're using libpq (because you mention PQcmdStatus),
>then after declaring a cursor and FETCH ALL, try
>
>1.3.4. Retrieving SELECT Result Information
>
> PQntuples Returns the number of tuples (rows) in the query result.
>
> int PQntuples(const PGresult *res);
>
>I'm not exactly sure what you're trying to achieve or going to do,
>so if I misunderstood you, ask again.
>
>Regards, Christoph
Thanks for your reply.
What I'm trying to do is the following: I want to browse through a view
containing more than 10000 records. To avoid slowing things down too much,
I would like my client program to receive (through the network) only the
records that are to be displayed on the screen. I believe I could do this
by declaring a cursor and then fetching the parts of the resultset I need.
It would be useful to know the size of the resultset immediately after the
cursor has been declared. How do I get this information? I could of course
fetch all of the resultset, but that is what I am trying to avoid.
Shouldn't it be quicker to perform a move through the set than fetching it?
I found that moving zero records results in a move to the end of the
resultset, with a command status returning the number of records moved.
Although I expected this method to take less time than a fetch (does it?),
I was wondering if there might be another way to get the size of the
resultset that can be fetched through the declared cursor.
KP
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: k.p.d.lehre@basalmed.uio.no, ch@rodos.fzk.de
Subject: Re: length of recordset read through a cursor
In-Reply-To: <5.2.0.9.2.20030805123048.01415ed8@uio-pop.uio.no>
References: <5.2.0.9.2.20030805123048.01415ed8@uio-pop.uio.no>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox