PostgreSQL with Rails, using iLIKE to search a combined two fields?
using PostgreSQL in Rails, I have the the following condition:
['fname || lname || [fname, lname] ILIKE ?', "%#{search}%"]
Search is the user input given to find a user.
I want that to sear开发者_如何转开发ch against fname and lname, that works fine... But if the user searches for james b, looking for james bond, it break, no results are found.
So I want to combine fname with lname (james bond).
I tried brackets, that error'd how do I combine the two in PostgresSQL + rails?
Try this:
Concatenate the two columns as a third column and search from the third column:
SELECT CONCAT(fname, ' ', lname) as fullname FROM table
精彩评论