I am using sqlalchemy
to fetch data from tables.
Right now fetching all records from a table called audit_trail_table
is working as expected.
select_stmt = select([self.audit_trail_table]).where(self.audit_trail_table.c.id == int(id))
row = conn.execute(select_stmt).fetchone()
Now I wish to execute LIKE
queries on multiple columns as follows:
filter_query = #(some value which will work as a filter_query while fetching )records
filter_stmt = select([self.audit_trail_table]).where(self.audit_trail_table.c.first_name like '%' + filter_query + '%' or self.audit_trail_table.c.last_name like '%')
But it gives an error at LIKE. How can I achieve this?
You can use the like
operator:
select([self.audit_trail_table]).where(
self.audit_trail_table.c.first_name.like('%' + filter_query + '%') or
self.audit_trail_table.c.last_name.like('%abc%')
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With