sql - Unique sort order for postgres pagination -


while trying implement pagination server side in postgres, came across point while using limit , offset keywords have provide order clause on unique column primary key.

in case using uuid generation pkeys can't rely on sequential order of increasing keys. order pkey desc - might not result in newer rows on top always. resorted using created date column - timestamp column should unique.

but question comes if ui client wants sort other column? in event might not unique column resort order user_column, created_dt desc maintain predictable results postgres pagination.

is right approach? not sure if going right way. please advise.

i talked exact problem on old blog post (in context of using orm):

one last note using sorting , paging in conjunction. query implements paging can have odd results if order clause not include field represents empirical sequence in data; sort order not guaranteed beyond explicitly specified in order clause in (maybe all) database engines. example: if have 100 orders occurred on exact same date, , ask first page of data sorted date, ask second page of data sorted same way, entirely possible of data duplicated across both pages. depending on query , distribution of data “sortable,” can practice include unique field (like primary key) final field in sort clause if implementing paging.

http://psandler.wordpress.com/2009/11/20/dynamic-search-objects-part-5sorting/


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -