Double query (limit and offset) - Mailing list pgsql-sql

From Michael Landin Hostbaek
Subject Double query (limit and offset)
Date
Msg-id 20051011151105.GA29943@mich2.itxmarket.com
Whole thread Raw
Responses Re: Double query (limit and offset)  (Janning Vygen <vygen@gmx.de>)
Re: Double query (limit and offset)  (Richard Huxton <dev@archonet.com>)
List pgsql-sql
List, 

I'm using the OFFSET / LIMIT combo in order to split up my query, so it
only parses 20 rows at a time (for my php-scripted webpage).

I'm using two queries; the first basically doing a select count(*) from
[bla bla]; the second grabbing the actual data while setting LIMIT and
OFFSET. 

In addition, I'm using the first query plus some calculations to parse
total hits to the query, and number of pages etc etc.

Now, my problem is this, the first query is simply counting all rows
from the main table, whereas the second query has plenty of JOINS, and a
GROUB BY statement - it's a fairly heavy query. The total (reported by
the first query), it not at all the same as the amount of rows returned
by the second query. I'd like to avoid having to run the "heavy" query
twice, just in order to get the number of rows.

Is there a smarter way of doing it ? 

Thanks, 

/mich


pgsql-sql by date:

Previous
From: "Vikas J"
Date:
Subject: Problem -Postgre sql
Next
From: "Stewart Ben (RBAU/EQS4) *"
Date:
Subject: Re: Problem while using start transaction ans commit;