Skip site navigation (1) Skip section navigation (2)

How do I detect End-of-table or End-of-limit ?

From: "Jan van der Weijde" <Jan(dot)van(dot)der(dot)Weijde(at)attachmate(dot)com>
To: <pgsql-interfaces(at)postgresql(dot)org>
Subject: How do I detect End-of-table or End-of-limit ?
Date: 2007-01-11 10:30:48
Message-ID: 4B9C73D1EB78FE4A81475AE8A553B3C67DC52B@exch-lei1.attachmate.com (view raw or flat)
Thread:
Lists: pgsql-interfaces
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. 
 
Of course there are workarounds:
count the number of records (but if the size of the table or select set
is a multiple of my LIMIT value that does not work)
or
just try another SELECT and if the FECTH NEXT will fail again I'm done
 
However I am looking for something more elegant like a status flag in
libpq that indicate EOF or End-Of-limit.
 
Thank you,
Jan van der Weijde

Responses

pgsql-interfaces by date

Next:From: Alvaro HerreraDate: 2007-01-12 00:36:41
Subject: Re: How do I detect End-of-table or End-of-limit ?
Previous:From: L BayukDate: 2007-01-10 00:41:00
Subject: Re: BCC55 and libpq 8.2

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group