From: | Merlin Moncure <mmoncure(at)gmail(dot)com> |
---|---|
To: | Scott Bailey <artacus(at)comcast(dot)net> |
Cc: | junaid malik <junaidmalik14(at)gmail(dot)com>, pgsql-general(at)postgresql(dot)org |
Subject: | Re: count function alternative in postgres |
Date: | 2010-04-05 18:19:51 |
Message-ID: | z2lb42b73151004051119mf98800fepde4f5d648a628d5c@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Sat, Apr 3, 2010 at 3:02 PM, Scott Bailey <artacus(at)comcast(dot)net> wrote:
> junaid malik wrote:
>>
>> 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.
>>
>> Reference url is given below
>>
>>
>> http://dev.mysql.com/doc/refman/5.1/en/group-by-functions.html#function_count-distinct
>>
>> Thanks
>>
>
> I already answered your question on dbforums.com. But in Postgres you can
> do:
>
> SELECT COUNT( DISTINCT row(col1, col2, col3) ) FROM foo
> or
> SELECT COUNT( DISTINCT (col1, col2, col3) ) FROM foo
very clever! This is similar to how I use rowtypes to get around the
single column restrictions on function calls in the select field list.
merlin
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2010-04-05 18:47:06 | Re: count function alternative in postgres |
Previous Message | Alban Hertroys | 2010-04-05 17:34:13 | Re: How to fix set-valued function called in contextthat cannot accept a set in earlier versions |