简体   繁体   English

SQLAlchemy 查询如何使用 MySQL 的 REGEXP 运算符?

[英]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.

相关问题 如何在带有 sqlalchemy 的 sqlite 中使用 regexp 函数? - How to use regexp function in sqlite with sqlalchemy? 如何在MySQL中使用Flask(不使用sqlalchemy-原始SQL查询)? - How to use Flask with mysql (without sqlalchemy - raw sql query)? 如何使用SQLAlchemy的`one_or_none`查询方法? - How to use SQLAlchemy's `one_or_none` query method? 如何使用@>运算符构建具有过滤器的sqlalchemy查询? - How to build a sqlalchemy query that has a filter with the @> operator? 如何在sqlalchemy中使用条件运算符or_ with conditional if? - How to use conditional operator or_ in sqlalchemy with conditional if? 如何使用 SQLAlchemy 做“mysql 解释” - How can I use SQLAlchemy to do “mysql explain” 对于SQLAlchemy查询,如何将ilike搜索运算符与in_运算符组合? - For an SQLAlchemy query, how to combine ilike search operator with in_ operator? 如何使用 SQLite 在 SQLAlchemy 中执行 REGEXP_REPLACE? - How can I do REGEXP_REPLACE in SQLAlchemy with SQLite? Sqlalchemy:当字符串在左边而列在右边时使用 PSQL 的`~` 运算符 - Sqlalchemy: use PSQL's `~` operator when string is on left and column on right 如何在SQLAlchemy的SQL表达式语言上使用JSON_OBJECTAGG编写MySQL查询? - How do you write MySQL query using JSON_OBJECTAGG on SQLAlchemy's SQL Expression Language?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM