python - flask-sqlalchemy where in 子句查询语法是什么?

标签 python flask flask-sqlalchemy

我正在使用 flask-sqlalchemy,我的问题是 where in 子句如下:

select * from table_1 where id in (1,2,3,5)
OR
select * from table_1 where field_1_id in (select id from table_2 where .... )

和 get_or_create 像 peewee orm

Object.get_or_create(.......)

我如何用 flask-sqlalchemy 生成这个句子?

最佳答案

尝试 .in_ clause在 sqlalchemy 中

result = db_session.query(table_1).filter(table_1.id.in_((1,2,3,5))).all()

注意:这里假设 table_1 是您的模型

关于python - flask-sqlalchemy where in 子句查询语法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22420598/

相关文章:

python - 正在寻找一种更好的方法来为字典、全局整数生成键?

python - 如何在单个地方处理 flask 中的一般异常?

heroku - 我应该如何在 Heroku 上运行 Alembic 迁移?

python - Flask-sqlalchemy;通过外键列表过滤查询

python - 请用好的例子解释生成器和迭代器的概念

python - 池.apply_async() : nested function is not executed

python - 没有名为 libxml2 的模块 - Linux Mint Rafaela (Ubuntu 14.04)

python - SQLalchemy 具有一对一关系的批量插入

python - 如何使用棉花糖序列化自定义 sqlalchemy 字段?

python - Flask-sqlalchemy 属性错误 : 'function' object has no attribute 'query'