When trying to implement pagination on the server side in postgres, I came across a point that, when using the restriction and offset keywords, should provide an ORDER BY clause in a unique column, possibly a primary key.
In my case, I use UUID generation for Pkeys, so I cannot rely on the sequential order of increasing keys. ORDER BY pkey DESC - may not cause new lines to appear on top. Therefore, I resorted to using the "Date Created" column - a timestamp column that should be unique.
But my question arises if the UI client wants to sort some other column? in case it may not always be a unique column, I turn to ORDER BY user_column, created_dt DESC to maintain predictable results for pagination on postgres pages.
Is this the right approach? I'm not sure if I will return correctly. please inform.
source share