Postgres默认按ID排序-Worldship [英] Postgres default sort by id - worldship

查看:99
本文介绍了Postgres默认按ID排序-Worldship的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要设置世界飞船来从我们的postgres数据库之一中提取。我需要它,以便程序包按ID排序。我没有办法(我知道)让shipship发送order by子句,因此我需要将返回的记录的默认值设置为由id返回。

I need to setup worldship to pull from one of our postgres databases. I need to have it so that the packages are sorted by id. I have no way (that i am aware of) of having worldship send the order by clause so I need to have the default for the records returned to be returned by id.

第二点,我不知道在上次更改记录时,postgres default如何对它进行排序,如果我写了两个记录,则为1,2然后在运行查询时更改记录2,它将返回记录2,即第一个记录。

On a second note I have no idea how postgres default sorts it looks like it by the last time the record was changed so if i write a two records id 1,2 then change record 2 when I run the query it returns them with record 2 being first.

推荐答案

行以未指定的顺序返回,根据sql规范,除非您添加order by子句。在Postgres中,这意味着您将基本上获得活动行在磁盘上读取的顺序。

Rows are returned in an unspecified order, per sql specs, unless you add an order by clause. In Postgres, that means you'll get rows in, basically, the order that live rows read on the disk.

如果您想要一致的顺序而无需添加order by子句,请按照杰克的注释中的建议创建一个视图。

If you want a consistent order without needing to add an order by clause, create a view as suggested in Jack's comment.

这篇关于Postgres默认按ID排序-Worldship的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆