pythonsqlalchemy

Using OR in SQLAlchemy


I've looked through the docs and I cant seem to find out how to do an OR query in SQLAlchemy. I just want to do this query.

SELECT address FROM addressbook WHERE city='boston' AND (lastname='bulger' OR firstname='whitey')

Should be something like

addr = session.query(AddressBook).filter(City == "boston").filter(????)

Solution

  • From the tutorial:

    from sqlalchemy import or_
    filter(or_(User.name == 'ed', User.name == 'wendy'))