How to nest conjunctions or_ and and_ in SQLAlchamey

﹥>﹥吖頭↗ 提交于 2020-01-05 08:10:52

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!