I’m using the following query to search for users:
@users = User.find( :all,
:select => 'users.*',
:conditions => ["lower(fname) || ' ' || lower(lname) LIKE ?", '%'+"#{params[:q].downcase}"+'%'],
)
This works great for examples like so:
Bob S find Bob Smith
Bob finds Bob Smith
Problem is
Bob Smith does not find Bob Smith
How can I get the query above to return an exact match? Thanks
The query is just plain wrong. First, ‘||’ is not a concatenation operator. Second, the operator precedence makes it evaluated as:
which is not what you want. I guess you would like it:
EDIT: So you can use:
EDIT2: The above is wrong, I haven’t noticed it was about Postgresql. There is a ‘||’ concatenation operator in Postgres of course. I’m not deleting this post because of the comments below but don’t use it please.