user1344280
user1344280

Reputation:

SQLite - Selecting rows from table using a comparer function

I have a table in my SQLite database where one of the columns is just a free text. Also, I have a custom function defined that calculates the Levenshtein distance of two given strings. Basically is just a comparer function that returns an integer value (distance between both strings).

My goal is to retrieve ALL the rows from that table that share a distance lower than a given value D between them.

Is this possible using queries? I thought GROUP BY would be the answer but I haven't gotten any semi decent results I can share.

Thanks in advance for any help provided.

Upvotes: 0

Views: 163

Answers (1)

CL.
CL.

Reputation: 180080

You have to join the table with itself:

SELECT *
FROM MyTable T1 JOIN
     MyTable T2 ON T1.ID < T2.ID AND
                   LDist(T1.TextColumn, T2.TextColumn) < 42

(The ID comparison prevents returning two result records for the same pair.)

Upvotes: 0

Related Questions