Re: [SQL] count() question - Mailing list pgsql-sql

From Peter Eisentraut
Subject Re: [SQL] count() question
Date
Msg-id Pine.LNX.4.21.9912181655230.356-100000@localhost.localdomain
Whole thread Raw
In response to count() question  ("Mitch Vincent" <mitch@venux.net>)
List pgsql-sql
On 1999-12-17, Mitch Vincent mentioned:

> So my question is, is there anyway you can get the total number of results
> (using count() or something) and still use the limit directive in the same
> query? I tried looking at the number of result rows too but 10 (the limit)
> is all I come up with.
> 
> I would really like to avoid doing 2 full queries here, if anyone has any
> suggestions please let me know.

Why do you want to avoid that? If you need two different results then you
probably have to use two different queries. I assume you need the count to
display something like "x matches found" and use LIMIT/OFFSET to step
through them page by page. In that case there is really no way but to
query twice. If your query is really complicated and slow you might want
to put the complete query results in a temporary table, and select the
count and the to-be-displayed data from there.


-- 
Peter Eisentraut                  Sernanders väg 10:115
peter_e@gmx.net                   75262 Uppsala
http://yi.org/peter-e/            Sweden




pgsql-sql by date:

Previous
From: Peter Eisentraut
Date:
Subject: Re: [SQL] making 'like' queries quicker
Next
From: admin
Date:
Subject: Re: [SQL] making 'like' queries quicker