我正在尝试使用 SQLAlchemy ORM 以相反的顺序执行 where 子句。所以与其Table.query.filter(Table.column.like(value))
,我更想以...
select * from table where 'mail.google.com' like domain;
。要选择此行:
|域名 ||------------ ||%.google.com |
理想情况下,我将能够做到这一点:
Table.query.filter(BinaryExpression('mail.google.com', Table.domain, custom_op('like')).all()
但它返回 AttributeError:"str"对象没有属性"self_group"。
这在SQLAlchemy中是如何表达的?
这对
我有用。
from sqlalchemy.sql.expression import literal
Table.query.filter(literal('mail.google.com').like(Table.domain)