X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 3989F53745 for ; Fri, 8 Apr 2005 17:51:43 +0100 (BST) 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 76821-06 for ; Fri, 8 Apr 2005 16:51:38 +0000 (GMT) Received: from tht.net (vista.tht.net [216.126.88.2]) by svr1.postgresql.org (Postfix) with ESMTP id 393A853743 for ; Fri, 8 Apr 2005 17:51:37 +0100 (BST) Received: from dyn-70-66.tor.dsl.tht.net (dyn-70-66.tor.dsl.tht.net [134.22.70.66]) by tht.net (Postfix) with ESMTP id 0F2A976A27; Fri, 8 Apr 2005 12:51:37 -0400 (EDT) Subject: Re: getting count for a specific querry From: Rod Taylor To: Tom Lane Cc: pgsql-sql@postgresql.org, Joel Fradkin , Ragnar =?ISO-8859-1?Q?Hafsta=F0?= In-Reply-To: <15084.1112977923@sss.pgh.pa.us> References: <000001c53c3e$f4f5b730$797ba8c0@jfradkin> <1112977546.7447.39.camel@localhost.localdomain> <15084.1112977923@sss.pgh.pa.us> Content-Type: text/plain Date: Fri, 08 Apr 2005 12:51:32 -0400 Message-Id: <1112979092.92363.250.camel@home> Mime-Version: 1.0 X-Mailer: Evolution 2.2.1.1 FreeBSD GNOME Team Port Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.008 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200504/101 X-Sequence-Number: 20994 > > select * from mytable where somecondition AND uniquecol>? > > ORDER by uniquecol limit 50 OFFSET 50; > > > where the ? is placeholder for last value returned by last query. > > Uh, you don't want the OFFSET there do you? But otherwise, yeah, > this is a popular solution for paging through some rows. Doesn't really > help with the problem of counting the total dataset though ... In the past I've done an EXPLAIN and parsed the plan to see what PostgreSQL estimated for the number of . If less than $threshhold, I would do a count(*). If more than $threshhold I would display to the user "approx N records". This seemed to be good enough for most cases. --