Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use ILIKE for multiple values in single column in rails?

How to use ILIKE for multiple values in single column.

This is the solution for multiple values without using like condition:

Project.where(name: ["Arvind Oasis", "Prestige Jindal City"])

In this example, it is taking the exact matches in my database. but i want to take similar matches for all the values.

How to use ILIKE for multiple values ["Arvind Oasis", "Rajkumar Jindal City"]

For single values i can use like this,

Project.where("name ILIKE ?", "%Prestige Kumar%")
like image 576
Rajkumar Ulaganadhan Avatar asked May 30 '19 14:05

Rajkumar Ulaganadhan


2 Answers

Use:

Project.where("name ILIKE ANY (array[?])", ["%Arvind Oasis%", "%Prestige Jindal City%", "%XXXX%"])
like image 117
Boris BRESCIANI Avatar answered Nov 15 '22 02:11

Boris BRESCIANI


You can try postgres SIMILAR TO operator like below

Project.where("name similar to '%(Arvind\sOasis|Rajkumar\sJindal\sCity)%'")

like image 45
Arivarasan L Avatar answered Nov 15 '22 03:11

Arivarasan L