wizard Woodland Wizard

postgres cursor query

To avoid slow OFFSET queries in postgres, you can use FETCH NEXT.

This uses a cursor based approach which means the query stays consistent even if you are many pages deep.

SELECT *
FROM sales
ORDER BY sale_date DESC
OFFSET 10
FETCH NEXT 10 ROWS ONLY;

references

programming