我想在SQL Alchamey中重新创建此查询,但我无法嵌套过滤器:
查询:
SELECT * FROM calendar
where (recurrenceRule = '')
or (recurrenceRule != '' and start < @end1);
的Python:
events.filter(or_(Calendar.recurrenceRule!='',
(Calendar.recurrenceRule=='',Calendar.start>=filterStart))
此python导致以下异常: &#34;预期的SQL表达式对象或字符串。&#34;
答案 0 :(得分:2)
您必须明确使用and_
:
events.filter(or_(
Calendar.recurrenceRule!='',
and_(Calendar.recurrenceRule=='', Calendar.start>=filterStart))
)