See OFFSET and LIMIT in PostgreSQL.
Your request for page 5 may look like this:
SELECT *
FROM tbl
ORDER BY id
OFFSET 400
LIMIT 100;
idis the main key in my example, so the index is in place automatically. If you access the table so much, performance can benefit from using CLUSTER .
Total Pages:
SELECT ceil(1235::real / 100)::int
FROM tbl;
If you want the number to be rounded, simply simplify:
SELECT 1235 / 100
FROM tbl;
If both numbers are integers, the result will be integer, and fractional digits will be truncated automatically. But I think you need to round here.
source
share