在 SQLAlchemy 中使用 OR [英] Using OR in SQLAlchemy

查看:47
本文介绍了在 SQLAlchemy 中使用 OR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我查看了通过文档,但我似乎无法找到如何在 SQLAlchemy 中进行 OR 查询.我只想做这个查询.

I've looked through the docs and I cant seem to find out how to do an OR query in SQLAlchemy. I just want to do this query.

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

应该是这样的

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

推荐答案

来自 教程:

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

这篇关于在 SQLAlchemy 中使用 OR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆