sqlalchemy filter_by in list code example

Example 1: sqlalchemy filter or

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

Example 2: sqlalchemy filter by relationship

patients = Patient.query.filter(Patient.mother.has(phenoscore=10))

Example 3: sqlalchemy _in array sqlite

session.query(MyUserClass).filter(MyUserClass.id.in_((123,456))).all()

Example 4: sqlalchemy core in clause

session.execute(
    select(
        [MyUserTable.c.id, MyUserTable.c.name], 
        MyUserTable.c.id.in_((123, 456))
    )
).fetchall()

Tags:

Sql Example