I want to find a value in the database without considering case sensitivity. For example I have a value msg = “Join” in my DB …I want to find the exact value even if I search for it like this
select * where msg = 'JoiN'
select * where msg = 'JoiN'
select * where msg = 'joiN'
select * where msg = 'jOIN'
here is the query i wrote
def is_valid_msg?(msg) do
message
|> where([a], fragment("charindex(lower(?), lower(?)) > 0", ^remove_spaces(msg), a.text) and a.status == "A")
|> select([:id, :msg])
|> Repo.one()
end
def remove_spaces(msg) do
msg
|> String.replace(~r/ +/, " ")
|> String.trim()
end