D
D
Daniil Laptev2014-11-03 10:55:44
PostgreSQL
Daniil Laptev, 2014-11-03 10:55:44

How to search for a combination of two values ​​in postgresql?

There is a users table with two columns name and lastname , can I somehow search for records by the totality of the values ​​of these columns? So that you can search by name, by surname and by name and surname at once.
where(name || lastname LIKE ?', "...") - this query searches only by first name or last name.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
tsarevfs, 2014-11-03
@TakteS

Logical operators will help you.

V
Viktor Vsk, 2014-11-03
@viktorvsk

It's good practice to use https://github.com/activerecord-hackery/ransack
This will allow you to write something like this:
User.search(name_or_lastname_cont: "имя")

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question