Re: counting distinct rows on more than one column

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: counting distinct rows on more than one column
Дата
Msg-id 19360.985809099@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: counting distinct rows on more than one column  (Dirk Lutzebaeck <lutzeb@aeccom.com>)
Список pgsql-sql
Dirk Lutzebaeck <lutzeb@aeccom.com> writes:
> Michael Fork writes:
>>> In 7.0.3, I believe the following would work:
>>> 
>>> SELECT count(distinct(a || b)) FROM t;

> Great, this works! I don't quite get it why...

Michael really should not have proposed that solution without mentioning
its limitations: it's not actually counting distinct values of the column
pair a,b, but only of their textual concatenation.  For example a = 'xy'
and b = 'z' will look the same as a = 'x' and b = 'yz'.

If there is some character you never use in column A, say '|', you
could do count(distinct(a || '|' || b)) with some safety, but this
strikes me as still a pretty fragile approach.
        regards, tom lane


В списке pgsql-sql по дате отправления:

Предыдущее
От: Dirk Lutzebaeck
Дата:
Сообщение: Re: counting distinct rows on more than one column
Следующее
От: Stephan Szabo
Дата:
Сообщение: Re: DELETE FROM fails with error