0

This is how I do fuzzy string search in postgresql:

select * from table where levenshtein(name, 'value') < 2;

But what can I do if the 'name' colum contains array?

P.S.: It is necessary to use index. And this is the difference.

kz_sergey
  • 677
  • 5
  • 19
  • Possible duplicate of [Using Levenshtein function on each element in a tsvector?](https://stackoverflow.com/questions/12100983/using-levenshtein-function-on-each-element-in-a-tsvector) – Kaushik Nayak Dec 09 '17 at 19:39
  • You can use elastic search too! – Tilak Putta Dec 10 '17 at 09:24
  • I see two solutions: 1) unnest 2) second table, that emulates unnest. Does unnest use index? What if there are many unnested array fields? – kz_sergey Dec 11 '17 at 22:36

1 Answers1

0

You can use unnest() over the array:

select  * from
(
    select unnest(name) as name_in_array, id from 
    (
    select 1 as id, ARRAY['value1','valu','lav'] as name
    union all
    select 2 as id, ARRAY['value2','orange','yellow'] as name
    )t1
) t2
where levenshtein(name_in_array, 'value') < 2;
Roee Anuar
  • 3,071
  • 1
  • 19
  • 33