更新时间:2023-10-22 14:58:40
在我看来,你永远不应该依赖顺序.
You should NEVER depend on the order in my honest opinion.
根据 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.
MySQL 倾向于按照行的插入顺序返回行,这就是为什么您会看到不同的行为.
MySQL tends to return rows in the order they're inserted, and this is why you see the different in behavior.
如果您希望它们始终按照创建的顺序返回,您可以使用 Item.order("created_at")
If you want them to always be returned in the order they were created, you can use Item.order("created_at")