参考这里的过滤示例:https://sqlmodel.tiangolo.com/tutorial/where/#filter-rows-using-where-with-sqlmodel,如何获取年龄为null的所有英雄。
我需要相当于:
select * from hero where age is null这样做是可行的:
select(Hero).where(Hero.age != None)但是,IDE抱怨PEP 8: E711 comparison to None should be 'if cond is not None:'
所以我把它改成:
select(Hero).where(Hero.age is None)但是,它不像预期的那样工作,导致生成不正确的SQL:
SELECT * FROM hero WHERE 0 = 1什么是正确的方法?
发布于 2022-06-25 13:35:03
from sqlalchemy.sql.operators import is_
stmt = select(Hero).where(is_(Hero.age, None))
result = session.exec(stmt)https://stackoverflow.com/questions/72754269
复制相似问题