Paginating in PostgreSQL: Knowing when to add next link -


i reading guide on postgresql pagination here. now, using seek method near bottom, looks this:

select * news category_id = 1234 , (date, id) < (prev_date, prev_id)  order date desc, id desc limit 10; 

after query runs, need determine if need add 'next' link page, doing grabbing count of rows date , id less date , id returned query. need next link infinite scroll plugin using. there better way determine if there rows left after query done?

one simple way ask 11 rows, though you're showing 10. if 11th row present, there more data , need next link.

this way don't have ask counts, run 1 query. again, if data doesn't change, getting count once , caching might more efficient. might bit error prone.

the minus side retrieve maybe 10% more data, depending on table structure may or may not affect performance also.


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -