4

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)

1 Answer 1

10

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')
)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.