Re: Postgresql GROUP BY "SIMILAR" but not equal values

Поиск
Список
Период
Сортировка
От Gauthier, Dave
Тема Re: Postgresql GROUP BY "SIMILAR" but not equal values
Дата
Msg-id 0AD01C53605506449BA127FB8B99E5E179DB8055@FMSMSX114.amr.corp.intel.com
обсуждение исходный текст
Ответ на Re: Postgresql GROUP BY "SIMILAR" but not equal values  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-general
What about a regexp match ?

-----Original Message-----
From: pgsql-general-owner@postgresql.org [mailto:pgsql-general-owner@postgresql.org] On Behalf Of Tom Lane
Sent: Thursday, February 06, 2014 10:32 AM
To: alexandros_e
Cc: pgsql-general@postgresql.org
Subject: Re: [GENERAL] Postgresql GROUP BY "SIMILAR" but not equal values

alexandros_e <alexandros.ef@gmail.com> writes:
> Is there a way in SQL or PostgreSQL in general to group by values than
> are not exactly the same but are quite similar (like 'ABC' and 'ABCD')
> based on some distance function (levenshtein for example) if the
> distance is within some threshold (i.e., 1)

Well, you can GROUP BY the result of a function.

You are going to have to think harder than the above in any case.
For example, it's not hard to imagine a "similarity" operator that says that A is similar to B, and B is similar to C,
butif you ask it to compare A to C it says they're not similar (enough).  Now what? 
Are A,B,C all part of the same group?  If you take the transitive closure of such an operator you probably end up with
everythingin one group; but if you don't, it's hard to see a principled result at all. 

If you can cast your problem as transformation of the values into some canonical or representative form, then you can
dothat and then group on simple equality of the canonical values.  For instance case-insensitive grouping is
customarilydone with 

      GROUP BY lower(x)

            regards, tom lane


--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


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

Предыдущее
От: Sergey Konoplev
Дата:
Сообщение: Re: Postgresql GROUP BY "SIMILAR" but not equal values
Следующее
От: Bret Stern
Дата:
Сообщение: Re: Help with connection issue - started today