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

标签 python sqlalchemy

这个SQL如何查询:

SELECT * from table where field REGEXP 'apple|banna|pear';

使用 SQLAlchemy 编写?

我的基本查询如下所示:

query = session.query(TableFruitsDTO)

最佳答案

SQLAlchemy 文档描述了 how to use the MySQL REGEXP operator .由于没有内置函数,使用 .op() 创建函数:

query = session.query(TableFruitsDTO).filter(
     TableFruitsDTO.field.op('regexp')(r'apple|banana|pear')
)

关于python - SQLAlchemy 查询如何使用 MySQL 的 REGEXP 运算符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27228635/

相关文章:

python - 无法使用 MySQL 数据写入文件

python - Python 中的自定义颜色图

python - json2html,Python : json data not converted to html

python - 子属性上的 SQLAlchemy 查询过滤器

python - 使用 sqlalchemy 获取插入行的数量

python - RuntimeError:OrderedDict在迭代过程中发生了突变(Python3)

python - --extract-audio等同于YoutubeDL类?

python - 如何创建使用 groupby 的 column_properties?

sqlalchemy - 按关系中的项目数过滤结果

python - SQLAlchemy session 错误 : InvalidRequestError