Re: Yet Another COUNT(*)...WHERE...question - Mailing list pgsql-general

From Gregory Stark
Subject Re: Yet Another COUNT(*)...WHERE...question
Date
Msg-id 87hcmzwwal.fsf@oxford.xeocode.com
Whole thread Raw
In response to Re: Yet Another COUNT(*)...WHERE...question  (Rainer Bauer <usenet@munnin.com>)
List pgsql-general
"Rainer Bauer" <usenet@munnin.com> writes:

> Anyway, what Phoenix is trying to say is that 2 queries are required: One to
> get the total count and one to get the tuples for the current page. I reckon
> it would help, if the query returning the result set could also report the
> total no. of tuples found. Somthing like
> SELECT COUNT(*), *  FROM <table> WHERE <cond> OFFSET <o> LIMIT <l>
>
> Or is there a way to do that?

Well anything like the above would just report l as the count.

The only way to do it in Postgres currently is to create a temporary table.
Then you can populate it once, then select the count from the temporary table
in one query and the required page from it in the second query.

But temporary tables in Postgres are not really designed for this. In
particular they count as DDL so you have to grant privileges to create tables
to the application and it has to create and delete entries in pg_class for
every use.

--
  Gregory Stark
  EnterpriseDB          http://www.enterprisedb.com

pgsql-general by date:

Previous
From: hubert depesz lubaczewski
Date:
Subject: how to get id of currently executed query?
Next
From: "Trevor Talbot"
Date:
Subject: Re: Yet Another COUNT(*)...WHERE...question