Find rows where text array contains value similar to input

前端 未结 4 1261
失恋的感觉
失恋的感觉 2020-12-06 18:44

I\'m trying to get rows where a column of type text[] contains a value similar to some user input.

What I\'ve thought and done so far is to use the

4条回答
  •  旧时难觅i
    2020-12-06 19:14

    An admittedly imperfect possibility might be to use ARRAY_TO_STRING, then use LIKE against the result. For example:

    SELECT *
    FROM someTable
    WHERE ARRAY_TO_STRING(someColum, '||') LIKE '%someInput%';
    

    This approach is potentially problematic, though, because someone could search over two array elements if they discover the joining character sequence. For example, an array of {'Hi','Mom'}, connected with || would return a result if the user had entered i||M in place of someInput. Instead, the expectation would probably be that there would be no result in that case since neither Hi nor Mom individually contain the i||M sequence of characters.

提交回复
热议问题