Finding partial strings in ecto using ilike

I am trying to search the database to see if a row matches part of another row in the database. I can make it match if they are exact using ilike, but when I search only part of the string, it does not catch the data containing it. This is what my code for the request looks like:

    servicesstate = Repo.all(from p in Callme.Service, where: ilike(p.locations, ^zip.state))

It will match when the values ​​are accurate (South Carolina, South Carolina), but I want it to match when it's something like (Located in South Carolina, South Carolina)

thank

+4
source share
1 answer

% LIKE/ILIKE:

servicesstate = Repo.all(from p in Callme.Service, where: ilike(p.locations, ^"%#{zip.state}%"))

, , zip.state %. %, Ecto.Query.API.fragment/1 .

+10

Source: https://habr.com/ru/post/1648685/


All Articles