| От | 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 по дате отправления:
Сайт использует файлы cookie для корректной работы и повышения удобства. Нажимая кнопку «Принять» или продолжая пользоваться сайтом, вы соглашаетесь на их использование в соответствии с Политикой в отношении обработки cookie ООО «ППГ», в том числе на передачу данных из файлов cookie сторонним статистическим и рекламным службам. Вы можете управлять настройками cookie через параметры вашего браузера