2015-12-21 112 views
0

SELECT id, created_at FROM "location_reviews" ORDER BY created_at DESC;PostgreSQL的順序通過,並限制不返回預期的行

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)?相反,它返回的查詢沒有OFFSETcreated_at列的類型爲timestamp without time zone

回答

1

看起來created_at在這些行中具有相同的值。在這種情況下,您應該在ORDER BY中添加另一個字段。否則,行爲沒有定義 - PostgreSQL可以根據需要對它們進行排序。