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

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -