Reputation: 4979
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)
Upvotes: 4
Views: 3985
Reputation: 127360
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')
)
Upvotes: 10