AnApprentice
AnApprentice

Reputation: 111060

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 search 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?

Upvotes: 0

Views: 1144

Answers (1)

Jasdeep Singh
Jasdeep Singh

Reputation: 3326

Try this:

Concatenate the two columns as a third column and search from the third column:

   SELECT CONCAT(fname, ' ', lname) as fullname FROM table

Upvotes: 1

Related Questions