Re: count function alternative in postgres

Поиск
Список
Период
Сортировка
От Merlin Moncure
Тема Re: count function alternative in postgres
Дата
Msg-id z2lb42b73151004051119mf98800fepde4f5d648a628d5c@mail.gmail.com
обсуждение исходный текст
Ответ на Re: count function alternative in postgres  (Scott Bailey <artacus@comcast.net>)
Ответы Re: count function alternative in postgres  (Tom Lane <tgl@sss.pgh.pa.us>)
Список 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 по дате отправления:

Предыдущее
От: Alban Hertroys
Дата:
Сообщение: Re: How to fix set-valued function called in contextthat cannot accept a set in earlier versions
Следующее
От: Tom Lane
Дата:
Сообщение: Re: count function alternative in postgres