问题
I'm tyring to recreate this query in SQL Alchamey but I've been unable to nest the filters:
Query:
SELECT * FROM calendar
where (recurrenceRule = '')
or (recurrenceRule != '' and start < @end1);
Python:
events.filter(or_(Calendar.recurrenceRule!='',
(Calendar.recurrenceRule=='',Calendar.start>=filterStart))
This python results in the following exception: "SQL expression object or string expected."
回答1:
You must use and_
explicitly:
events.filter(or_(
Calendar.recurrenceRule!='',
and_(Calendar.recurrenceRule=='', Calendar.start>=filterStart))
)
来源:https://stackoverflow.com/questions/26154009/how-to-nest-conjunctions-or-and-and-in-sqlalchamey