Is PostgreSQL order fully guaranteed if sorting on a non-unique attribute? [duplicate]

懵懂的女人 提交于 2019-12-04 23:30:08

Order is not guaranteed unless you explicitly specify it with the ORDER BY clause.

You might be getting data in the same order upon several executions in case there is no database activity, as PostgreSQL will just return rows in the order it finds them in the database pages. Do a small test:

  • insert a number of rows keeping the desired order;
  • query the table: you will get rows ordered;
  • update the very first record in the set;
  • query the table again;
  • observe the results.

In short: You might be even getting rows in the desired order, but this is just a coincidence.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!