Get the latest tech news

Keyset cursors, not offsets, for Postgres pagination


We're building Sequin, a Postgres CDC tool to streams and queues like Kafka, SQS, HTTP endpoints, and more. Efficient, correct pagination is paramount for our backfill process, so we use keyset cursors extensively. You've probably heard about the limitations of offset/limit in Postgres. There are two primary concerns with

We're building Sequin, a Postgres CDC tool to streams and queues like Kafka, SQS, HTTP endpoints, and more. If you're doing a one-time sweep of a table and want to avoid seeing a row twice, one easy solution is to start your pagination by first grabbing a max keyset cursor: So this can work if after the initial request, you drop params like limit and order and move to using nextPage and previousPage to traverse.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of Postgres

Postgres

Photo of offsets

offsets

Photo of Keyset

Keyset

Related news:

News photo

Crunchy Data Warehouse: Postgres with Iceberg for High Performance Analytics

News photo

South Africa Proposes Carbon Tax Changes to Increase Offsets

News photo

PgPDF: Pdf Type and Functions for Postgres