Re: How to get the total number of rows returned by query

From: Shridhar Daithankar <shridhar_daithankar(at)persistent(dot)co(dot)in>
To: Pgsql-General <pgsql-general(at)postgresql(dot)org>
Subject: Re: How to get the total number of rows returned by query
Date: 2003-09-23 14:58:57
Message-ID: 3F705FB1.5020804@persistent.co.in
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Egor Shipovalov wrote:

> I'm implementing paging through search results using cursors. Is there a
> better way to know total number of rows under a cursor than running a
> separate COUNT(*) query? I think PostgreSQL is bound to know this number
> after the first FETCH, isn't it?

Using libpq, yes. You can use PQntuples. See
http://developer.postgresql.org/docs/postgres/libpq-exec.html#LIBPQ-EXEC-SELECT-INFO

Unfortunately this will retrieve the entire resultselt before returning the
control. When libpq will have chuncking of data, this will be much more
flexible, as you are expecting it now, I guess.

Shridhar

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Stephan Szabo 2003-09-23 15:03:53 Re: Foreign key constraint accepted even when not same
Previous Message Bruno Wolff III 2003-09-23 14:55:41 Re: table size