Re: count function alternative in postgres

From: junaidmalik14 <junaidmalik14(at)gmail(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: count function alternative in postgres
Date: 2010-04-23 10:45:08
Message-ID: 28339793.post@talk.nabble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql


Thanks Ben. It works fine.

Junaid.

Ben Morrow-2 wrote:
>
> Quoth junaidmalik14(at)gmail(dot)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
>
>
> --
> Sent via pgsql-sql mailing list (pgsql-sql(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-sql
>
>

--
View this message in context: http://old.nabble.com/count-function-alternative-in-postgres-tp28126792p28339793.html
Sent from the PostgreSQL - sql mailing list archive at Nabble.com.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Andreas 2010-04-26 00:12:43 How to find broken UTF-8 characters ?
Previous Message junaidmalik14 2010-04-23 10:44:10 Re: count function alternative in postgres