postgresql - psycopg2游标获取结果集的所有顺序

标签 postgresql psycopg2 python-3.7 postgresql-9.4

我有一个应用程序服务器 API,它连接到我们的 postgres 后端并使用 psycopg2 连接和游标对象执行 HAS ORDER BY 子句的查询。

当我调用cursor.fetchall()时,我可以假设结果集中元组的顺序始终与执行查询中的 ORDER BY 子句确定的顺序相同吗?

换句话说,我可以安全地假设 psycopg2.cursor 不会打乱结果集元组的原始顺序吗?

谢谢你, 普拉纳夫

最佳答案

是的,顺序被保留。

查询已经执行并且结果可用。 fetchone()、fetchmany() 和 fetchall() 保留游标结果列表的原始顺序。

关于postgresql - psycopg2游标获取结果集的所有顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58086415/

相关文章:

django - 连接到位于 "localhost"的服务器,端口 5432 失败 : Connection refused Is the server running on that host and accepting TCP/IP connections?

python - 使用 PyQt 连接到 Sqlalchemy 数据库并将数据库内容保存到 PyQt 中的 TableView

python - Postgres/psycopg2 - 插入字符串数组

python - 在 Ubuntu 12.04 中安装 psycopg2 时出错

python - 没有名为 'mysql' 的模块 python 问题

sql - jsonb_array_elements 获取元素位置

ruby-on-rails - 初始查询后的 ActiveRecord 预加载

python - Psycopg2 中的 `TypeError: argument 2 must be a connection, cursor or None`

python - 如何在Python中保存迭代器的状态?

python - 如何在Python 3中安装texttract?