Concepts
Cursors and state
How incremental tables find where to read from, how large loads commit along the way, and logged state for positions the data can't carry.
An incremental table has a cursor_column, such as updated_at or id. Each run reads from the
destination’s maximum of that column. SQLLoad stores the position nowhere else, so a table you
change, truncate or drop by hand is followed on the next run.
[sources.app.tables."public.orders"]description = "Orders, one row per order."write_strategy = "merge"unique_key = "{primary_key}"cursor_column = "updated_at"$ sqlload plan -v app__orders… ├── reads updated_at >= 2026-10-12 16:00:00.000+00 (warehouse maximum)…Cursor settings
Section titled “Cursor settings”| Setting | Meaning |
|---|---|
cursor_column |
An integer, date, timestamp or text column, or a list of one type family, such as ["updated_at", "created_at"]: the first non-NULL in each row. |
null_cursor |
fail (default), include or ignore. See NULL cursor values. |
cursor_start |
Where the first run starts. Without it, the first run reads everything. |
lookback |
Read this far before the maximum, for late rows: "1h" or "2d" on a date or timestamp cursor, a number on an integer cursor. Not with append. |
lookback_from |
destination (default) or now, the time of the run. Date and timestamp cursors. See Reload a window. |
lookahead |
Read only values before now plus this; on a date cursor, up to today plus that many days. Date and timestamp cursors. |
append_cursor_inclusive |
true makes append read from the maximum, not after it, inserting its rows again. See append. |
batch_size |
Commit one window at a time, such as "7d" or 1000. See Batches. |
on_cursor_out_of_range |
Python tables only: fail (default), skip or warn. See Rows outside the window. |
timezone |
Zone for times without an offset, such as "Europe/Paris"; UTC by default. See Times without an offset. |
The read starts at the first of these that applies, and plan shows which on the reads line:
--start-cursor(or--start-cursor-ts/--start-cursor-int).- With
lookback_from = "now": now minuslookback, on every run. - The destination’s maximum, minus
lookback.appendreads strictly after it (>inplan). cursor_start, when the table is empty.- Everything.
Text cursors compare by Unicode code point, so 'B1' comes before 'a9': use keys that increase in
that order, such as zero-padded numbers, ULIDs or ISO timestamps. On Postgres, index a text cursor
as (event_key COLLATE "C") so reads can use the index. DuckDB, BigQuery and Databricks follow a
collation set on the dataset, schema, table or column.
NULL cursor values
Section titled “NULL cursor values”A row whose cursor is NULL loads on the first run and is never read again: a later edit, or a new row with a NULL cursor, never loads. So by default a table with such rows fails:
$ sqlload load…failed raw.app__orders 2 source rows have a NULL updated_at, which an incremental read never selects, so they would never load; set null_cursor = "include" to read them on every run, list a column that is always set to coalesce with it (such as cursor_column = ["updated_at", "created_at"]), or set null_cursor = "ignore" to skip them…A database or warehouse source counts them before reading, so nothing is written. A Python table counts as it reads, so earlier windows stay committed.
| Fix | Effect |
|---|---|
cursor_column = ["updated_at", "created_at"] |
Use the first non-NULL column. A row where all are NULL follows null_cursor. |
null_cursor = "include" |
Read NULL-cursor rows on every run as well. merge only. |
null_cursor = "ignore" |
Skip them. |
plan shows the rule at the end of the reads line, such as (NULL cursors: included).
The count is one more source query per read: a sequential scan on Postgres without an index on the
cursor, and a billed query job on BigQuery (see BigQuery permissions).
include, ignore and a column the source declares NOT NULL skip it.
A Python table, a files source, a files target and delete_insert take one cursor_column, not a
list. A Python function that filters by ctx.cursor_value itself must yield NULL-cursor rows too,
or SQLLoad can’t count them.
Backfilling a range
Section titled “Backfilling a range”--start-cursor and --end-cursor read from the start up to, not including, the end. Values are an
integer, an RFC 3339 timestamp or a date, typed from each table’s cursor:
$ sqlload plan -v app__orders --start-cursor 2026-10-01 --end-cursor 2026-10-08… ├── reads updated_at from 2026-10-01 00:00:00.000000+00 (--start-cursor), below 2026-10-08 00:00:00.000000+00 (--end-cursor)…Every selected table must have the same kind of cursor. To range integer and time cursors in one
run, use the typed flags instead: --start-cursor-ts/--end-cursor-ts for date and timestamp
cursors, --start-cursor-int/--end-cursor-int for integers. A table given only the other kind
fails plan. A date cursor refuses a time of day, and a text cursor takes only the untyped flags.
Fiscal year tables
Section titled “Fiscal year tables”On an integer cursor, lookback counts back that many cursor units. An ERP table keyed only by
fiscal_year can reload the latest year and the one before, so late adjustments land after the
year-end close:
[sources.erp.tables."public.gl_balances"]description = "General ledger balances, one row per account and fiscal period."write_strategy = "delete_insert"cursor_column = "fiscal_year"lookback = 1$ sqlload plan -v erp__gl_balances… ├── reads fiscal_year >= 2025 (warehouse maximum 2026 minus lookback 1)…plan refuses a lookback that doesn’t fit the cursor, or is 0 or less. Text cursors take none.
--start-cursor overrides it.
Batches
Section titled “Batches”A large load commits along the way, so after a failure the next run carries on from the last
commit. plan -v shows each table’s commits line.
| Table | Commits |
|---|---|
batch_size = "1d" or 1000 |
Each window, up to 100,000 windows (32,767 for a Snowflake unload). A Python table is called once per window. |
Postgres table whose cursor_column leads an index |
About every 1 GB, in cursor order, between distinct cursor values. batch_size = "none" opts out. |
Other cursor tables, text cursors, append without a cursor or logged state |
Once per read. |
| Files sources | Every 1,000 files or about 1 GB; see Which files load. |
replace and --reload |
Once, at the end, by swapping in the new table. |
ClickHouse delete_insert, append and merge |
Once, at the end; a merge also every 10 million waiting rows. A stopped run publishes nothing since its last commit, so split long backfills with --end-cursor. See ClickHouse write strategies. |
[sources.app.tables."public.orders"]description = "Orders, one row per order."write_strategy = "merge"unique_key = "{primary_key}"cursor_column = "updated_at"cursor_start = "2026-09-01"batch_size = "7d"$ sqlload plan -v… ├── reads updated_at >= 2026-09-01 00:00:00.000+00 (first run, …) ├── commits 11 windows of 7 days, one commit each…The first run needs cursor_start or --start-cursor. An integer batch_size also needs
--end-cursor, except on Postgres, which stops at the maximum when plan ran. --reload with
batch_size rebuilds the table from only the windows it reads; see Reloading.
A large append, merge or delete_insert into DuckDB or MotherDuck may also commit in
pieces. If an append stops partway, the next load of that
table removes the partial rows and warns. Don’t run two loads of the same table at once.
Reading windows at once
Section titled “Reading windows at once”A Postgres table with batch_size can read several windows at once, while still committing them
one at a time in order. Opt in at the top of the project, then set batch_concurrency (at most 16)
on the table or its source:
microbatch_concurrency = true
[sources.app.tables."public.events"]description = "Events, one row per event."write_strategy = "delete_insert"cursor_column = "occurred_at"cursor_start = "2026-01-01"batch_size = "1d"batch_concurrency = 4Each window uses its own source connection, and all share one snapshot. Windows read ahead wait in
the target’s staging_dir or the system temporary folder. It helps when reads are slower than
commits.
Rows outside the window
Section titled “Rows outside the window”A Python table is asked for one window at a time, from ctx.cursor_value to ctx.cursor_end, and
SQLLoad checks the rows it returns against it. on_cursor_out_of_range decides what happens to
rows outside:
| Value | Rows outside a window |
|---|---|
fail (default) |
The table fails, naming the rows and the likely cause. The window doesn’t commit. |
skip |
Dropped with a warning. Their own window reads them. |
warn |
Loaded with a warning. |
An API that filters by whole days returns the boundary day twice:
$ sqlload load --end-cursor "2026-09-15 00:00:00"…failed raw.shop__orders the function returned 24 rows outside the window it was asked for, updated_at >= 2026-09-01 00:00:00+00:00 and < 2026-09-08 00:00:00+00:00: 24 after its end, 2026-09-08 00:00:00+00:00 → 2026-09-08 23:00:00+00:00, the first at row 169 (updated_at 2026-09-08 00:00:00+00:00); all on 2026-09-08, the day the window ends: the API may filter by whole days. Loading them would move the cursor past rows not read yet. If it does, set on_cursor_out_of_range = "skip": the next window reads them.skip suits that API: each boundary day loads once, in its own window.
Times without an offset
Section titled “Times without an offset”On a cursor of times, timezone sets the zone of a cursor_start, --start-cursor or
--end-cursor without an offset. A Python table’s ctx.cursor_value and ctx.cursor_end arrive
in that zone; without timezone, in UTC, or naive on a timestamp_ntz cursor. See
The context.
$ sqlload plan -v --start-cursor "2026-09-03 00:00:00" --end-cursor "2026-09-05 00:00:00"… ├── reads updated_at from 2026-09-03 00:00:00 (--start-cursor), below 2026-09-05 00:00:00 (--end-cursor); rows outside a window fail the table; times without an offset in Europe/Paris (the table's timezone)…A time the zone skips when its clocks go forward fails plan; a time it has twice is the earlier.
A date cursor has no zone: lookahead, lookback_from = "now" and today are counted in UTC.
Logged state
Section titled “Logged state”Some positions aren’t in the data, such as an API’s sync token. A Python table with
state="logged" keeps its position in ctx.state, and SQLLoad records it with each commit in an
append-only run log.
@shop.table(write_strategy="append", state="logged")def events(ctx: sl.Context): """Shop events, read page by page with a sync token.""" token = ctx.state while True: page = fetch_events(since=token) yield from page.items token = page.next_token or token yield sl.checkpoint(token) if not page.has_more: breakctx.stateis the last successful run’s position:Noneon the first run, after--reloadand afterlogged-state reset --clear.yield sl.checkpoint(token)after a page’s rows marks what they cover, as any JSON value. A failed run resumes from the last committed checkpoint without loading a row twice. Rows after the last checkpoint load again, unless the function leaves the final position inctx.state.sl.checkpoint(None)clears the position, so keep the last real token, asor tokendoes.- Without checkpoints, assign
ctx.stateonce per page: underappendthe next run may load up to about two pages again. Assigning more often can lose rows after a crash.
The run log is the _sqlload_runs table in the table’s schema, or <table folder>/_sqlload/runs/ on
a files target. With a cursor_column too, the data wins when they disagree. Deleting the log is
safe: the next run reads as a stateless one would.
Inspecting and correcting the log
Section titled “Inspecting and correcting the log”$ sqlload logged-state showraw.shop__events state 4 (run 54ab366a-bca1-4088-9723-4c6d1723ad02 at 2026-11-09T18:02:47.844103Z) 2026-11-09T18:02:47.552256Z e1bf5051-3333-4fdd-aa31-18bf2d74a51c run - -> -, state 2 6 rows 2026-11-09T18:02:47.844103Z 54ab366a-bca1-4088-9723-4c6d1723ad02 run - -> -, state 4 6 rowsverify compares the logged cursor with the data, reconcile --yes adopts the data’s, and
reset --to VALUE --yes or --clear sets or forgets the position. Corrections are appended. An
unreadable record blocks only its table until a reset. See sqlload logged-state.