How can this SQL query:
SELECT * from table where field REGEXP 'apple|banna|pear';
be written using SQLAlchemy?
My base query looks like this:
query = session.query(TableFruitsDTO)
The SQLAlchemy docs describe how to use the MySQL REGEXP operator . Since there is no built-in function, use .op()
to create the function:
query = session.query(TableFruitsDTO).filter(
TableFruitsDTO.field.op('regexp')(r'apple|banana|pear')
)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.