4 ms·
That multi column answer doesn't seem to address pagination of queries where some of the columns are in descending order and some aren't. I implemented a keyse
by djrobstep 6y ago
That multi column answer doesn't seem to address pagination of queries where some of the columns are in descending order and some aren't.
I implemented a keyset paging library for sqlalchemy which supports this, and found the nicest way to do it is to swap the comparisons for the descending columns. For instance if this is an all-ascending paginated query:
select ... where row(c1, c2, c3) > row(11, 12, 13) order by c1, c2, c3
Then with c2 descending it would look like this:
select ... where row(c1, 12, c3) > row(11, c2, 13) order by c1, c2 desc, c3