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 EFF0F3A3FE8 for ; Tue, 16 Nov 2004 19:46:03 +0000 (GMT) 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 65422-07 for ; Tue, 16 Nov 2004 19:45:49 +0000 (GMT) Received: from window.monsterlabs.com (window.monsterlabs.com [216.183.105.176]) by svr1.postgresql.org (Postfix) with SMTP id C09B43A3FC2 for ; Tue, 16 Nov 2004 19:45:48 +0000 (GMT) Received: (qmail 12681 invoked from network); 16 Nov 2004 19:45:47 -0000 Received: from w080.z064003242.bna-tn.dsl.cnc.net (HELO ?192.168.1.22?) (64.3.242.80) by 0 with SMTP; 16 Nov 2004 19:45:47 -0000 Mime-Version: 1.0 (Apple Message framework v619) Content-Transfer-Encoding: 7bit Message-Id: <1B2F7B00-3808-11D9-95C2-000D93AE0944@sitening.com> Content-Type: text/plain; charset=US-ASCII; format=flowed To: PgSQL - SQL From: Thomas F.O'Connell Subject: Counting Distinct Records Date: Tue, 16 Nov 2004 13:45:45 -0600 X-Mailer: Apple Mail (2.619) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests=LINES_OF_YELLING X-Spam-Level: X-Archive-Number: 200411/155 X-Sequence-Number: 19474 I am wondering whether the following two forms of SELECT statements are logically equivalent: SELECT COUNT( DISTINCT table.column ) ... and SELECT DISTINCT COUNT( * ) ... If they are the same, then why is the latter query much slower in postgres when applied to the same FROM and WHERE clauses? Furthermore, is there a better way of performing this sort of operation in postgres (or just in SQL in general)? Thanks! -tfo -- Thomas F. O'Connell Co-Founder, Information Architect Sitening, LLC http://www.sitening.com/ 110 30th Avenue North, Suite 6 Nashville, TN 37203-6320 615-260-0005