you were close, you need to build the following query in sqla:
root@localhost [inDB]> SELECT * FROM Person; +-----------+------------+-----------+ | person_id | first_name | last_name | +-----------+------------+-----------+ | 1 | Bob | Smith | | 2 | John | Smith | +-----------+------------+-----------+ 2 rows in set (0.00 sec) root@localhost [inDB]> SELECT * FROM Person WHERE CONCAT(first_name, ' ', last_name) LIKE 'Bob Sm%'; +-----------+------------+-----------+ | person_id | first_name | last_name | +-----------+------------+-----------+ | 1 | Bob | Smith | +-----------+------------+-----------+
then it becomes clear that you need a filter with the concat () function:
from sqlalchemy import func res = session.query(Person).filter(func.concat(Person.first_name, ' ', Person.last_name).like('Bob Sm%')).all() len(res)
source share