我从Postgres得到了博客文章列表
select id, post_priority, publish_start
from posts
where email = 'someuser@gmail.com'
ORDER BY publish_start DESC
如果有许多文章发表同一日期,则该列表有误。
当我从Postgres 10.2(服务器Ubuntu)中检索到时
id | title | post_priority | publish_start ------+-------+----------------------+---------------- 1001 | A... | 1 | 2019-09-05 1002 | B... | 2 | 2019-09-05
从开发机器中检索出来的情况与众不同-Postgres 11(MacOS)
id | title | post_priority | publish_start ------+-------+----------------------+---------------- 1002 | B... | 2 | 2019-09-05 1001 | A... | 1 | 2019-09-05
我知道我只需要在查询中再添加一列即可。但是我仍然想知道,当所有文章的publish_start日期都相同时,是什么决定了默认排序?如何更改/配置该默认列?
如果两行(或更多行)的order by
玫瑰列顺序中指定的列的值相同,则未定义。
获得稳定和有保证的排序顺序的唯一方法是将其添加post_priority
到order by
列中。