From: | "Phoenix Kiula" <phoenix(dot)kiula(at)gmail(dot)com> |
---|---|
To: | "Rainer Bauer" <usenet(at)munnin(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Yet Another COUNT(*)...WHERE...question |
Date: | 2007-08-16 15:35:05 |
Message-ID: | e373d31e0708160835h5f3372at77192011915f8cec@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On 16/08/07, Rainer Bauer <usenet(at)munnin(dot)com> wrote:
> Gregory Stark wrote:
>
> >"Rainer Bauer" <usenet(at)munnin(dot)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.
>
> True, but what about this:
>
> SELECT (SELECT COUNT(*) FROM <table> WHERE <cond>), * FROM <table> WHERE <cond> OFFSET <o> LIMIT <l>
>
Whoa, this may not please SQL puritans but I love it! And yes, it is
cached. I find the idea of temporary tables and storing counts for
different 'slices' of my data untenable with all the complex mishmash
of triggers and such. The count(*) query seems to take a bit in the
beginning but works ok thereafter because it seems to be auto-cached.
Sweet. Thanks for sharing!!
From | Date | Subject | |
---|---|---|---|
Next Message | Bill Moran | 2007-08-16 15:35:57 | Re: Yet Another COUNT(*)...WHERE...question |
Previous Message | madhtr | 2007-08-16 15:21:45 | Re: pqlib in c++: PQconnectStart PQconnectPoll |