我该如何表达“像列一样的"值"?在SQLAlchemy中? [英] How do I express "WHERE 'value' like column" in SQLAlchemy?
本文介绍了我该如何表达“像列一样的"值"?在SQLAlchemy中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用SQLAlchemy ORM以相反的顺序编写where子句.所以我想以Table.query.filter(Table.column.like(value))
代替...
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;
...选择此行:
| domain |
| ------------ |
| %.google.com |
理想情况下,我可以这样做:
Ideally, I'd be able to do this:
Table.query.filter(BinaryExpression('mail.google.com', Table.domain, custom_op('like')).all()
但是它返回AttributeError:'str'对象没有属性'self_group'.
But it return the AttributeError: 'str' object has no attribute 'self_group'.
这在SQLAlchemy中如何表达?
How is this expressed in SQLAlchemy?
推荐答案
这对我有用.
from sqlalchemy.sql.expression import literal
Table.query.filter(literal('mail.google.com').like(Table.domain)
这篇关于我该如何表达“像列一样的"值"?在SQLAlchemy中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文