Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Array of values ILIKE some value

Lets say I have an array of strings returned by some subquery. And I want to make sure that at least one of the elements is matching with string (for example: ILIKE "%alex%"). What should I do for that? My code:

ANY(ARRAY["Alexander", "Michael", "John"]) ILIKE "%alex%"

is not working at all. I need a solution which will return true in my case, because one of the elements(Alexander) is ILIKE "%alex%".

like image 956
Alex Lance Avatar asked Apr 01 '26 15:04

Alex Lance


1 Answers

One approach is to use exists:

where exists (select 1 from unnest(ARRAY['Alexander', 'Michael', 'John']) el where el ILIKE '%alex%')
like image 194
Gordon Linoff Avatar answered Apr 04 '26 03:04

Gordon Linoff



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!