Received: from maia.hub.org (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id CD666634DAF for ; Tue, 6 Apr 2010 17:29:47 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 15939-06-3 for ; Tue, 6 Apr 2010 20:29:32 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from relay.pcl-ipout02.plus.net (relay.pcl-ipout02.plus.net [212.159.7.100]) by mail.postgresql.org (Postfix) with ESMTP id 319AD636288 for ; Tue, 6 Apr 2010 17:04:55 -0300 (ADT) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AvsEAI4wu0vUOFPl/2dsb2JhbACbOnG6YYUJBA Received: from plesk-mail01.plus.net ([212.56.83.229]) by relay.pcl-ipout02.plus.net with ESMTP; 06 Apr 2010 21:04:54 +0100 Received: (qmail 3601 invoked from network); 6 Apr 2010 18:47:33 +0000 Received: from host86-142-60-221.range86-142.btcentralplus.com (HELO osiris.mauzo.dyndns.org) (86.142.60.221) by plesk-mail01.plus.net with SMTP; 6 Apr 2010 18:47:26 +0000 Received: (qmail 3370 invoked by uid 1001); 6 Apr 2010 18:47:14 -0000 Date: Tue, 6 Apr 2010 19:47:14 +0100 From: Ben Morrow To: junaidmalik14@gmail.com, pgsql-sql@postgresql.org Subject: Re: count function alternative in postgres Message-ID: <20100406184714.GA3290@osiris.mauzo.dyndns.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <28126792.post@talk.nabble.com> X-Newsgroups: pgsql.sql Organization: Who, me? User-Agent: Mutt/1.5.20 (2009-06-14) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.821 tagged_above=-10 required=5 tests=AWL=-1.006, BAYES_40=-0.185, FAKE_REPLY_C=2.012 X-Spam-Level: X-Archive-Number: 201004/9 X-Sequence-Number: 33936 Quoth junaidmalik14@gmail.com (junaidmalik14): > > Is there any alternative of mysql function COUNT(DISTINCT expr,[expr...]) in > postgres. We get error if we > > write count like this count(distinct profile.id, profile.name, profile.age) > but it works well in mysql. Pg does support COUNT(DISTINCT ), but only for a single column. The best I can come up with for multiple columns is select count(distinct profile.tuple) from (select (id, name, age) as tuple from profile) as profile; or alternatively select count(*) from (select distinct (id, name, age) as tuple from profile) as profile; Ben