我sqlalchemy用来从表中获取数据。现在,从称为的表中获取所有记录audit_trail_table正在按预期方式工作。
sqlalchemy
audit_trail_table
select_stmt = select([self.audit_trail_table]).where(self.audit_trail_table.c.id == int(id)) row = conn.execute(select_stmt).fetchone()
现在,我希望LIKE对多个列执行查询,如下所示:
LIKE
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 '%')
但这给LIKE带来了错误。我怎样才能做到这一点?
请像运营商一样使用
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%'))
http://docs.sqlalchemy.org/en/rel_0_9/core/sqlelement.html#sqlalchemy.sql.operators.ColumnOperators.like