python - 在 SQLAlchemy 中使用 OR

我看过 through the docs而且我似乎无法找出如何在 SQLAlchemy 中进行 OR 查询。我只想做这个查询。

SELECT address FROM addressbook WHERE city='boston' AND (lastname='bulger' OR firstname='whitey')

应该是这样的

addr = session.query(AddressBook).filter(City == "boston").filter(????)

最佳答案

来自 tutorial :

from sqlalchemy import or_
filter(or_(User.name == 'ed', User.name == 'wendy'))

https://stackoverflow.com/questions/7942547/

相关文章:

python - 如何量化两个图像之间的差异?

python - 在 Python 2.6 中不推荐使用 BaseException.message

python - 多处理:如何在类中定义的函数上使用 Pool.map?

linux - 创建 .tar.gz 文件时排除目录

linux - 如何在 linux 上监控进程的线程数?

python - 如何在python中声明零数组(或一定大小的数组)

linux - 遍历 ls -l 输出的每一行

linux - 抑制makefile中命令调用的回声?

c - 线程有不同的堆吗?

python - 如何更改绘图背景颜色?