Re: count function alternative in postgres - Mailing list pgsql-general

From Merlin Moncure
Subject Re: count function alternative in postgres
Date
Msg-id z2lb42b73151004051119mf98800fepde4f5d648a628d5c@mail.gmail.com
Whole thread Raw
In response to Re: count function alternative in postgres  (Scott Bailey <artacus@comcast.net>)
Responses Re: count function alternative in postgres  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
On Sat, Apr 3, 2010 at 3:02 PM, Scott Bailey <artacus@comcast.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

pgsql-general by date:

Previous
From: Alban Hertroys
Date:
Subject: Re: How to fix set-valued function called in contextthat cannot accept a set in earlier versions
Next
From: Tom Lane
Date:
Subject: Re: count function alternative in postgres