简体   繁体   English

Postgresql中分页排序的排序问题

[英]Sorting issues for Pagination sorting in Postgresql

For pagination sorting am geting duplicated data once load the next page. 对于分页排序,一旦加载下一页,就会得到重复的数据。 For Eg: if a we have full name: Ahern in 1st page and after moving next page also sometimes we can able to see the same record. 例如:如果a是我们的全名:Ahern在第一页中,而在移动下一页之后,有时我们也可以看到相同的记录。 I need accurate data for each time for sorting a specific field. 我每次都需要准确的数据来对特定字段进行排序。 Am using order by as : ORDER BY Hourse :: numeric ASC LIMIT 50 OFFSET 50 我正在按以下方式使用订单:ORDER BY Hourse ::数字ASC LIMIT 50 OFFSET 50

Please suggest an accurate sorting method using in postgres sql. 请建议在postgres sql中使用的准确排序方法。

In order to use SQL LIMIT ... OFFSET ... as pagination for PostgreSQL you need to add ordering by unique value. 为了使用SQL LIMIT ... OFFSET ...作为PostgreSQL的分页,您需要按唯一值添加顺序。 Seems Hourse :: numeric is not unique over the table. 似乎Hourse :: numeric在表格中不是唯一的。

If you have an unique ID column, I would recommend to add this column as a second ordering argument, like ORDER BY Hourse :: numeric ASC, id ASC 如果您有唯一的ID列,我建议将该列作为第二个排序参数添加,例如ORDER BY Hourse :: numeric ASC, id ASC

PS. PS。 There is a brilliant article about Postgresql pagination tricks https://www.citusdata.com/blog/1872-joe-nelson/409-five-ways-paginate-postgres-basic-exotic 一篇关于Postgresql分页技巧的精彩文章https://www.citusdata.com/blog/1872-joe-nelson/409-five-ways-paginate-postgres-basic-exotic

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM