Postgresql命令并限制不返回预期的行

时间:2015-12-21 17:32:23

标签: postgresql

SELECT id, created_at FROM "location_reviews" ORDER BY created_at DESC;

 id  |     created_at
-----+---------------------
 251 | 2015-12-20 00:00:00
 426 | 2015-12-20 00:00:00
 357 | 2015-12-20 00:00:00

SELECT id, created_at FROM "location_reviews" ORDER BY created_at DESC LIMIT 1;

 id  |     created_at
-----+---------------------
 251 | 2015-12-20 00:00:00

SELECT id, created_at FROM "location_reviews" ORDER BY created_at DESC LIMIT 1 OFFSET 1;

 id  |     created_at
-----+---------------------
 251 | 2015-12-20 00:00:00

SELECT id, created_at FROM "location_reviews" ORDER BY created_at DESC LIMIT 1 OFFSET 2;

 id  |     created_at
-----+---------------------
 357 | 2015-12-20 00:00:00

为什么我的OFFSET 1查询不返回第二个条目(id = 426)?相反,它返回与没有OFFSET的查询相同的行。 created_at列的类型为timestamp without time zone

1 个答案:

答案 0 :(得分:1)

似乎ORDER BY在这些行中具有相同的值。在这种情况下,您应该在register_globals中添加另一个字段。否则,行为未定义 - PostgreSQL可以根据需要对它们进行排序。