Re: counting distinct rows on more than one column - Mailing list pgsql-sql

From Tom Lane
Subject Re: counting distinct rows on more than one column
Date
Msg-id 19360.985809099@sss.pgh.pa.us
Whole thread Raw
In response to Re: counting distinct rows on more than one column  (Dirk Lutzebaeck <lutzeb@aeccom.com>)
List 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 by date:

Previous
From: Dirk Lutzebaeck
Date:
Subject: Re: counting distinct rows on more than one column
Next
From: Stephan Szabo
Date:
Subject: Re: DELETE FROM fails with error