pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: L Bayuk <lbayuk@pobox.com>
To: Jan van der Weijde <Jan.van.der.Weijde@attachmate.com>
Cc: pgsql-interfaces@postgresql.org
Subject: Re: How do I detect End-of-table or End-of-limit ?
Date: Thu, 11 Jan 2007 19:41:45 -0500
Message-ID: <20070112004145.GA356@mail.mindspring.com> (raw)
In-Reply-To: <4B9C73D1EB78FE4A81475AE8A553B3C67DC52B@exch-lei1.attachmate.com>
References: <4B9C73D1EB78FE4A81475AE8A553B3C67DC52B@exch-lei1.attachmate.com>

On Thu, Jan 11, 2007 at 11:30:48AM +0100, Jan van der Weijde wrote:
> Hello all,
>  
> I am using the libpq interface method PQexec() to execute SELECT
> statements with a LIMIT clause. I declare a cursor with hold and use
> PQecec() to execute FETCH NEXT on that cursor.
> At a certain moment PQntuples() returns 0 after a fetch, but I cannot
> check for the actual reason: is the physical end of the table (or
> selection) reached or is the end of my limit reached.
> In the former case I'm done. But in the latter case I can continue
> selecting records by using SELECT with a LIMIT and OFFSET clause. 
>  ...

I'm not sure if this applies to you, but what I do is if I want N records,
I select with limit N+1. If I get N or fewer records back, it reached end
of table.  If I get N+1 back, I process the first N of them and discard the
last, and I know there are more records. Next query starts at the discarded
one.  So there is 1 record overlap on the queries. And unless the data
changes between queries, you will never get 0 records back.



view thread (4+ messages)  latest in thread

Message-ID: <20070112004145.GA356@mail.mindspring.com>
Permalink:  ../20070112004145.GA356@mail.mindspring.com/
Also on:    postgresql.org/message-id/20070112004145.GA356@mail.mindspring.com

 · 

reply

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 using the --to and --cc options:
  reply via email

  To: pgsql-interfaces@postgresql.org
  Cc: lbayuk@pobox.com, Jan.van.der.Weijde@attachmate.com
  Subject: Re: How do I detect End-of-table or End-of-limit ?
  In-Reply-To: <20070112004145.GA356@mail.mindspring.com>

* 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