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

Поиск
Список
Период
Сортировка
От L Bayuk
Тема Re: How do I detect End-of-table or End-of-limit ?
Дата
Msg-id 20070112004145.GA356@mail.mindspring.com
обсуждение исходный текст
Ответ на How do I detect End-of-table or End-of-limit ?  ("Jan van der Weijde" <Jan.van.der.Weijde@attachmate.com>)
Список pgsql-interfaces
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.


В списке pgsql-interfaces по дате отправления:

Предыдущее
От: Alvaro Herrera
Дата:
Сообщение: Re: How do I detect End-of-table or End-of-limit ?
Следующее
От: "Jan van der Weijde"
Дата:
Сообщение: Re: How do I detect End-of-table or End-of-limit ?