Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python SQLAlchemy将列添加到映射类上的查询()_Python_Postgresql_Orm_Pagination_Sqlalchemy - Fatal编程技术网

Python SQLAlchemy将列添加到映射类上的查询()

Python SQLAlchemy将列添加到映射类上的查询(),python,postgresql,orm,pagination,sqlalchemy,Python,Postgresql,Orm,Pagination,Sqlalchemy,我想做分页,我正在使用PostgreSQL。为了避免两次查询,我使用了 如何将full\u count列添加到查询中获取的列列表中。我可以使用query.add_columns,但在调用query.all()后无法访问该列 这在SQLAlchemy中是可能的吗?您能为您想要增加的查询提供原始代码吗?您使用的是SQLAlchemy核心还是声明式ORM?对于后者,它将如下所示: from sqlalchemy import func items = session.query(Model, fun

我想做分页,我正在使用PostgreSQL。为了避免两次查询,我使用了

如何将
full\u count
列添加到查询中获取的列列表中。我可以使用
query.add_columns
,但在调用
query.all()后无法访问该列


这在SQLAlchemy中是可能的吗?

您能为您想要增加的查询提供原始代码吗?您使用的是SQLAlchemy核心还是声明式ORM?对于后者,它将如下所示:

from sqlalchemy import func

items = session.query(Model, func.count().over().label('full_count')).all()
obj = items[0].Model
count = items[0].full_count

我不确定我以前在做什么,但肯定不是你建议的。您的解决方案正是我所需要的。有没有一种方法可以将“full_count”字段直接放置在模型上?因此,项[0]将返回与上述示例中的项[0]相同的模型,但项[0]除外。full_count将包含func.count()的结果?