开发者

PostgreSQL with Rails, using iLIKE to search a combined two fields?

开发者 https://www.devze.com 2023-01-27 02:59 出处:网络
using PostgreSQL in Rails, I have the the following condition: [\'fname || lname || [fname, lname] ILIKE ?\', \"%#{search}%\"]

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
0

精彩评论

暂无评论...
验证码 换一张
取 消