https://www.sqlalchemy.org/

Compare Date with DateTime

Cast the DateTime to Date

1
2
3
4
5
6
7
8
9
query = (session.query(
Obj.user_id.label('customer_id'),
func.count(Obj.id).label('total')
).
filter(
sqlalchemy.cast(Obj.date_time,Date) > Obj.some_date
).
group_by(Obj.user_id)
)
Reference:

1
2
3
4
5
6
7
8
9
10
11
query = (session.query(
FooModelClass.min.label('min'),
FooModelClass.max.label('max'),
FooModelClass.score.label('score'),
).
filter(
FooModelClass.min >= row.qty,
FooModelClass.max <= row.qty
)
)
print(str(query))

Output:

1
2
3
SELECT foo.min AS min, foo.max AS max, foo.score AS score
FROM foo
WHERE foo.min >= %s AND foo.max <= %s
Reference: