Dev Tools · 1h ago
PostgreSQL Query Pattern: Single SQL for Pagination With or Without Cursor
A developer shows how to use a single PostgreSQL query with an OR clause to handle both first-page and subsequent pagination, avoiding OFFSET. The pattern checks if the parameter is NULL to fetch all rows or filters by timestamp. This approach simplifies code but may risk suboptimal execution plans.
Meridian48 take
Clever SQL trick, but the performance trade-off between code simplicity and query plan optimization deserves scrutiny in production.
postgresqlpagination