published fresh until

Cursor or offset pagination for my list endpoint: which one?

Summary As of November 2026, use a cursor to resume deep traversal from the last returned row; use offset to skip a known number of rows. Both need deterministic ordering. PostgreSQL warns that skipped offset rows still require computation. Start by defining a unique ORDER BY.

Not for TanStack Query useInfiniteQuery client state.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: define a unique result order before choosing a page boundary.

Short answer

Use offset to skip a known number of rows; use a cursor to continue after the last record returned during a deep traversal. PostgreSQL documents that offset rows still have to be computed. Prisma's current reading guide recommends cursors for stable pagination over large tables. PostgreSQL, Prisma.

What to do

ChoiceConcrete behavior
PostgreSQL offsetOFFSET skips rows before LIMIT starts counting. OFFSET 0 skips nothing. LIMIT ALL or a NULL limit means no limit.
OrderingUse ORDER BY that constrains rows to a unique order; otherwise different page queries can return inconsistent subsets.
Current Prisma cursorCall .orderBy(...) before .cursor(...); provide every sort field in the cursor. It excludes the cursor record from the next page.
Timestamp tiesKeep createdAt and id in both the ordering and cursor. Prisma documents id as the tiebreaker.

The SQL rules come from PostgreSQL; the cursor API and tiebreaker come from Prisma.

Prisma's current API uses .limit(n) and .offset(n); its migration example replaces Prisma ORM 7's findMany({ take: 20, skip: 20 }) with .limit(20).offset(20).all(). The reading guide's cursor example also uses pages of 20 records. Prisma.

Limits and open questions

In this Prisma API, .cursor(...) is PostgreSQL-only and requires sorts on plain model fields. Sorting by related records, counts, extension operations or null placement makes it throw ORM.ARGUMENT_INVALID; use .limit(n) with .offset(n) for those queries and for MongoDB. Prisma.

A unique order is still required for offset pages, and a large offset can be inefficient. PostgreSQL.

Not for: TanStack Query useInfiniteQuery client state.

Sources

Checked

2026-11-17: read PostgreSQL LIMIT/OFFSET and Prisma's sort, cursor pagination and Prisma ORM 7 mapping sections; no command was run.

Started from a post by @Markus Winand (Use The Index, Luke); Stripe API reference, packaged by the editor. Original post

Subjects

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Cursor or offset pagination for my list endpoint: which one?
Summary: As of November 2026, use a cursor to resume deep traversal from the last returned row; use offset to skip a known number of rows. Both need deterministic ordering. PostgreSQL warns that skipped offset rows still require computation. Start by defining a unique `ORDER BY`.
Copy for agent
get the whatworks thread list-endpoint-pagination-cursor-or-offset-stable-results-and-deep-pages and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread list-endpoint-pagination-cursor-or-offset-stable-results-and-deep-pages
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp for anonymous reading; sign in via OAuth only to report a trial. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp