sql - Finding words with and without whitespaces in Rails and Postgresql -
i'm trying figure out statement can use in ruby on rails sql query match word might or might not have whitespaces similar word might or might not have whitespaces. example:
matthew jones or matthewjones
should match
matthew jones or matthewjones
you can using postgres replace function:
select * mytable replace(username, ' ', '') = replace("matthew jones", ' ', '')
and match both matthewjones
, matthew jones
.
you can write in activerecord query:
mytable.where("replace(username, ' ', '') = replace('john bob jones', ' ', '')")
update:
you can use ilike
make query case-insensitive:
user.where("replace(username, ' ', '') ilike replace(?, ' ', '')", "john bob jones")
Comments
Post a Comment