Re: How to get the total number of rows returned by query - Mailing list pgsql-general

From Shridhar Daithankar
Subject Re: How to get the total number of rows returned by query
Date
Msg-id 3F705FB1.5020804@persistent.co.in
Whole thread Raw
In response to How to get the total number of rows returned by query when using a cursor?  ("Egor Shipovalov" <pgsql_list@eonline.ru>)
Responses Re: How to get the total number of rows returned by query
List 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



pgsql-general by date:

Previous
From: Bruno Wolff III
Date:
Subject: Re: table size
Next
From: "Joshua D. Drake"
Date:
Subject: Re: PostgreSQL query failed: ERROR: pg_atoi: zero-length