[英]How can a SQLAlchemy query use MySQL's REGEXP operator?
How can this SQL query:这个 SQL 查询如何:
SELECT * from table where field REGEXP 'apple|banna|pear';
be written using SQLAlchemy?使用 SQLAlchemy 编写?
My base query looks like this:我的基本查询如下所示:
query = session.query(TableFruitsDTO)
The SQLAlchemy docs describe how to use the MySQL REGEXP operator . SQLAlchemy 文档描述了如何使用 MySQL REGEXP 运算符。 Since there is no built-in function, use .op()
to create the function:由于没有内置函数,所以使用.op()
创建函数:
query = session.query(TableFruitsDTO).filter(
TableFruitsDTO.field.op('regexp')(r'apple|banana|pear')
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.