I have this :
CREATE TABLE users
(
first_name varchar(60) NOT NULL,
last_name varchar(60) NOT NULL
);
INSERT INTO users
(first_name, last_name)
VALUES
('Sylvia ', 'Hoeks'),
('Harrison', 'Ford');
I get the list like this
SELECT first_name || ' ' || last_name AS user_full_name FROM users;
But I would like to be able to search on the column user_full_name
. Is it possible without a subquerie or CTE (like below)?
WITH users_list AS (
SELECT first_name || ' ' || last_name AS user_full_name
FROM users
)
SELECT * FROM users_list WHERE user_full_name ILIKE '%lvi%';
I tried with the first column !?
SELECT first_name || ' ' || last_name AS user_full_name FROM users WHERE 1 ILIKE '%lvi%';
/*
ERROR: operator does not exist: integer ~~* unknown
LINE 1: ...|| last_name AS user_full_name FROM users WHERE 1 ILIKE '%lv...
^
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
*/
I would like to be able to do something like this.
SELECT first_name || ' ' || last_name AS user_full_name FROM users WHERE user_full_name ILIKE '%lvi%';
For the moment I do:
SELECT first_name || ' ' || last_name AS user_full_name FROM users WHERE first_name ILIKE '%lvi%' OR last_name ILIKE '%lvi%';
Fiddle if needed : https://www.db-fiddle.com/f/c3HANw8M9W7kSVeEwidpne/0