问题
I'm trying to do a where clause in reverse order with SQLAlchemy ORM. So instead of Table.query.filter(Table.column.like(value))
, I'd like to end up with...
select * from table where 'mail.google.com' like domain;
...to select this row:
| domain | | ------------ | | %.google.com |
Ideally, I'd be able to do this:
Table.query.filter(BinaryExpression('mail.google.com', Table.domain, custom_op('like')).all()
But it return the AttributeError: 'str' object has no attribute 'self_group'.
How is this expressed in SQLAlchemy?
回答1:
This works for me.
from sqlalchemy.sql.expression import literal
Table.query.filter(literal('mail.google.com').like(Table.domain)
来源:https://stackoverflow.com/questions/46783346/how-do-i-express-where-value-like-column-in-sqlalchemy