X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id B6E56D7080 for ; Tue, 11 Oct 2005 12:11:12 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 30847-05 for ; Tue, 11 Oct 2005 15:11:07 +0000 (GMT) Received: from mail2.itxmarket.com (fw.itxmarket.com [213.11.40.109]) by svr1.postgresql.org (Postfix) with ESMTP id AA723D7047 for ; Tue, 11 Oct 2005 12:11:07 -0300 (ADT) Received: from icommerce.fr (mich2.itxmarket.com [192.168.2.26]) by mail2.itxmarket.com (Postfix) with ESMTP id 48B891C092B for ; Tue, 11 Oct 2005 17:11:05 +0200 (CEST) Received: by icommerce.fr (Postfix, from userid 1001) id 3D3C12282F; Tue, 11 Oct 2005 17:11:05 +0200 (CEST) Date: Tue, 11 Oct 2005 17:11:05 +0200 From: Michael Landin Hostbaek To: PostgresSQL list Subject: Double query (limit and offset) Message-ID: <20051011151105.GA29943@mich2.itxmarket.com> Mail-Followup-To: Michael Landin Hostbaek , PostgresSQL list Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Operating-System: FreeBSD 5.4-STABLE i386 X-PGP-Key: http://www.freebsdcluster.org/~mich/ User-Agent: Mutt/1.5.11 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.05 required=5 tests=[FORGED_RCVD_HELO=0.05] X-Spam-Level: X-Archive-Number: 200510/197 X-Sequence-Number: 23050 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