Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Principle:Mage ai Mage ai Paginated SQL Extraction

From Leeroopedia


Knowledge Sources
Domains Data_Integration, SQL, Pagination
Last Updated 2026-02-09 00:00 GMT

Overview

A paginated data extraction pattern that loads SQL database records in configurable batches using LIMIT/OFFSET with bookmark-based WHERE clause filtering.

Description

Paginated SQL Extraction addresses the challenge of extracting large datasets from SQL databases without overwhelming memory or network resources. Instead of loading all records in a single query, it uses LIMIT/OFFSET pagination to fetch records in batches (default batch size from BATCH_FETCH_LIMIT config). For incremental streams, it adds WHERE clauses using bookmark values to filter only new or updated records. The pagination loop continues until a batch returns fewer rows than the limit, indicating all data has been fetched.

Usage

Use this principle for any SQL database source connector where tables may contain large volumes of data. It is the default extraction mechanism for all SQL-based sources in the Mage integrations framework.

Theoretical Basis

The pagination algorithm:

  1. Set offset = 0, limit = fetch_limit (from config or BATCH_FETCH_LIMIT constant)
  2. Build SELECT query with selected columns FROM table
  3. If bookmarks exist, add WHERE clause (e.g., updated_at >= bookmark_value)
  4. Add ORDER BY (bookmark_properties, then key_properties, then unique_constraints)
  5. Add LIMIT {limit} OFFSET {offset}
  6. Execute query, yield batch of rows
  7. If len(rows) >= limit: increment offset, sleep(1), repeat from step 2
  8. If len(rows) < limit: stop pagination

Related Pages

Implemented By

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment