X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 331A6D1CA0F for ; Tue, 5 Aug 2003 11:15:26 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 97659-10 for ; Tue, 5 Aug 2003 08:14:10 -0300 (ADT) Received: from pat.uio.no (pat.uio.no [129.240.130.16]) by svr1.postgresql.org (Postfix) with ESMTP id 7C7F3D1C98F for ; Tue, 5 Aug 2003 08:15:14 -0300 (ADT) Received: from mail-mx1.uio.no ([129.240.10.29]) by pat.uio.no with esmtp (Exim 2.12 #7) id 19jzmd-0006xe-00; Tue, 5 Aug 2003 13:15:15 +0200 Received: from [129.240.130.64] (helo=snapp.uio.no) by mail-mx1.uio.no with esmtp (Exim 4.14) id 19jzmZ-0003yy-Hj; Tue, 05 Aug 2003 13:15:11 +0200 Received: from pk47st115.uio.no ([129.240.47.115] helo=pk-bpc-maritah.basalmed.uio.no) by snapp.uio.no with esmtp (Exim 2.12 #7) id 19jzmY-000309-00; Tue, 5 Aug 2003 13:15:10 +0200 Message-Id: <5.2.0.9.2.20030805123048.01415ed8@uio-pop.uio.no> X-Sender: knutle@uio-pop.uio.no X-Mailer: QUALCOMM Windows Eudora Version 5.2.0.9 Date: Tue, 05 Aug 2003 13:13:00 +0200 To: pgsql-sql@postgresql.org, Christoph Haller From: "Knut P. Lehre" Subject: Re: length of recordset read through a cursor Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed X-MailScanner-Information: This message has been scanned for viruses/spam. Contact postmaster@uio.no if you have questions about this scanning. X-UiO-MailScanner: No virus found X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200308/45 X-Sequence-Number: 14661 >> 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