Postgresql GROUP BY "SIMILAR" but not equal values

From: alexandros_e <alexandros(dot)ef(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Postgresql GROUP BY "SIMILAR" but not equal values
Date: 2014-02-06 15:18:15
Message-ID: 1391699895790-5790860.post@n5.nabble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I wanted to ask you the following question to all experts here.

Let's say I have this table foo

ID|G1|T1|
1|2|ABC|
1|2|ABCD|
1|2|DEF|
1|2|DEFG|

SELECT * FROM foo
GROUP BY ID,G1,T1

RETURNS exactly the same table.

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)

My intuition is that SQL cannot support such queries but I was wondering if
there was some hack around it. The problem as I see it that distance
functions require 2 values but GROUP BY only checks equality.

Another subproblem that might help is can we overload an operator of a
custom type, so that equals operator is more "relaxed" and is calculated by
a function? OR can we use GROUP BY with a custom comparator for a data
type?

I hope my question makes sense.

--
View this message in context: http://postgresql.1045698.n5.nabble.com/Postgresql-GROUP-BY-SIMILAR-but-not-equal-values-tp5790860.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Merlin Moncure 2014-02-06 15:29:40 Re: Help with connection issue - started today
Previous Message Merlin Moncure 2014-02-06 14:51:37 Re: Offending My Tender Sensibilities -OR- OLTP on a Star Schema