Concepts
Nested data
List fields as child tables with unnest, objects as columns with flatten: how child rows link to their parents, what each write strategy does with them, what unnest = "all" and flatten = "all" choose, and how names load.
unnest turns list fields into child tables, the way dlt does. A field that isn’t unnested, or
flattened, stays a JSON column.
[sources.orders.tables.orders]unnest = ["items", "items.parts", "tags"]With this, {"id": 1, "items": [{"sku": "a", "parts": [1, 2]}], "tags": ["x"]} loads:
| Table | Columns |
|---|---|
orders |
id and _sqlload_row_id, without items and tags |
orders__items |
sku, _sqlload_parent_id (its order’s row id), _sqlload_list_idx (its place in the list, from 0) and its own _sqlload_row_id |
orders__items__parts, orders__tags |
value, as each is a list of scalars, with the same link columns |
A list inside a list gives its item a list field, a level down. Child rows also carry
_sqlload_load_id and _sqlload_loaded_at. A NULL, missing or empty list gives no child rows.
Child tables take their columns from their rows and follow on_schema_change.
Settings
Section titled “Settings”| Setting | Meaning |
|---|---|
unnest |
Dotted paths of list fields, each with its parent listed too (items before items.parts), or "all". |
max_depth |
The most levels of child tables, 1000 by default. A deeper list stays JSON in its parent. It limits flatten too. |
columns |
Pins a child table’s column by its dotted path, such as "items.sku" = "text". Under contract = "enforced", a child table loads only the columns pinned so, plus its id and link columns. These keys aren’t checked against the data, so a misspelled one is ignored, and under enforced the field it meant is left out. |
row_id |
Always on with unnest; row_id = false fails plan. |
Write strategies
Section titled “Write strategies”| Strategy | Child tables |
|---|---|
append |
Each run’s child rows link to that run’s rows. |
replace, --reload |
Replaced with their parent. A child table no row reaches any more is emptied. |
merge |
A row’s id comes from its unique_key; its items carry it in _sqlload_root_id. Each commit replaces the merged rows’ items, so a list that shrank or went missing keeps only what it holds now. With repeated keys, only the kept row’s items load. Items an append loaded have no root id and stay. |
delete_insert |
Items carry their row’s id in _sqlload_root_id and leave with the rows a commit deletes. |
Child tables are written before their parent, after its checks pass. A load that fails between
the two can leave child rows with no parent, or merged rows without items, until a rerun, so join
child rows to their parent by _sqlload_parent_id.
Where child tables load
Section titled “Where child tables load”- Warehouses: DuckDB, MotherDuck, Postgres, BigQuery, Snowflake, ClickHouse and Databricks (Databricks tested against a stand-in for its API only). ClickHouse child tables have no sorting key or partitions, so each publish rebuilds the whole child table.
- Files targets: each child table in its own folder (
orders__items/besideorders/), underappendorreplacewith listed paths. Thepathmust use{table}and not the cursor. postgres_cdcsources, except into files targets, unnestjsonandjsonblists. An insert or update replaces its row’s items; a hard delete removes them. An update that leaves a TOASTed list out keeps them.- Files sources: SQLLoad splits the rows itself, so loads with
unnestare slower.
unnest = “all”
Section titled “unnest = “all””unnest = "all" unnests every list field, down to max_depth. Not on files targets.
- A field becomes a child table when its values so far, from the sampled files or a Python table’s first rows, are lists. NULL, missing and empty values decide nothing. Objects stay JSON.
- After that, a value that is neither a list nor NULL fails the load, naming the field. To keep a field as JSON, list the paths instead.
- A field with a child table from an earlier load (
<table>__<field>with a parent-id column) stays one. - A new list field follows
on_schema_change:ignoreleaves its items out with a warning.
Flattening objects
Section titled “Flattening objects”flatten loads an object’s keys as columns named <object>__<key>. It takes dotted paths, or
"all" for every object down to max_depth. An object it doesn’t flatten stays one JSON column
(VARIANT on Snowflake).
[sources.orders.tables.orders]unnest = ["items"]# paths reach inside unnested itemsflatten = ["customer", "customer.address", "items.dimensions"]- It works on Python tables and their
sl.httpjobs, JSON and NDJSON files, and the output of atransform. Any other source failsplan. - A path’s parent must be flattened or unnested too. A path may use the source’s spelling or the
loaded one (
LineTotalsorline_totals). - A NULL or missing object leaves its columns NULL. Lists are never flattened.
- Names go through
namingafter joining (customer__address__city). - The load fails when a listed path holds a scalar or a list, or a key’s column clashes with another column.
- Turning
flattenon for a table that holds the object as JSON leaves that column NULL from then on.
Under "all", plan lists each object it flattens (on a Python table, objects flatten at load)
and warns when one looks like a map whose keys are data: more than 20 keys, or most holding a digit
or not a plain name.
├── flatten every object, 1000 levels down at most │ customer → 3 columns (name, address__city, …) │ line_totals → 3 columns (sku_14, sku_99, …) │ ⚠ an object whose keys are data adds a column per key on every load; │ keep it as one column with columns = { line_totals = "json" }Keeping an object whole
Section titled “Keeping an object whole”Pin such a map as json to keep it, and everything under it, as one column; plan shows
kept as JSON: line_totals. A mask, or an exclude_columns or allow_columns name (not a
pattern), on an object also keeps it whole.
[sources.orders.tables.orders]flatten = "all"columns = { line_totals = "json" }plan fails on a listed path that is kept whole, on an exclude_columns or allow_columns pattern
that matches an object but none of its columns, and on any other pin of a flattened object:
columns line_totals = "text": flatten replaces line_totals with its keys' columns; pin it "json" to keep it wholeNaming
Section titled “Naming”Every table and column loads under a name the warehouse takes without quoting. A column’s name
goes through naming, rename, then on_duplicate_names; compat names the columns a load adds.
Set each on a source or table, naming and compat also on the target; the closest wins. For a
CSV header Order ID,OrderDate,Qty,Qty,Unit Price with
rename = { "Order ID" = "order_ref" }:
$ sqlload plan -v…└── raw.erp create table ├── order_ref int -> BIGINT ├── order_date text -> VARCHAR ├── qty int -> BIGINT ├── qty_1 int -> BIGINT ├── unit_price float -> DOUBLE… ├── columns 5, 3 named by snake_case: OrderDate -> order_date, Qty -> qty, ... ├── names Order ID -> order_ref (rename) │ Qty (column 4) -> qty_1 (numbered)…load prints the same names lines, and its JSON result gives
them in each table’s names.
naming
Section titled “naming”| Value | Names |
|---|---|
snake_case (default) |
As dlt’s default: Orders-V2 → orders_v2, OrderID → order_id. A name too long for the destination (63 characters on Postgres) is shortened with a tag, as dlt does. |
source |
The source’s names, quoted where needed. Table names from a table_name template are lower case. |
Settings and flatten paths may name a column either way (["OrderID"] or ["order_id"]). Any
other spelling fails plan:
unique_key column "orderid" is not a column of the table; did you mean OrderID (loads as order_id)?exclude_columns, allow_columns and skip_tables_with_columns match source names (accessToken,
or api_secret__key once flattened). A Python table’s ctx.cursor_column is the loaded name. The
target schema keeps the name it is given.
rename
Section titled “rename”rename is a map of source names (or their snake_case form) to loaded names, or the name of a
Python function:
python_paths = ["renames"]
[sources.erp.tables.orders]rename = "erp_names" # or a map: { "Order ID" = "order_ref" }import sqlload as sl
# registered as "erp_names"; @sl.rename("erp") picks another name@sl.renamedef erp_names(columns, ctx): return { c.position: "qty_returned" for c in columns if c.source == "Qty" and c.position > 2 }-
The function gets each column as an
sl.Column(positionfrom 1,source, anddefault, the name afternaming) andctx(source,table). It returns only the names it changes, by position. -
Functions are found on
python_paths, or passed directly:@shop.table(rename=erp_names). They run only in thesqlloadPython package’s command (uv tool install sqlload), not the standalone binary. -
planfails on a name no function or two functions have:rename erp_names: 2 functions are registered as erp_names, in renames/erp.py (erp_names) and renames/other.py (other_names); give one another name with @sl.rename("...") -
A rename to another column’s name fails
plan, whateveron_duplicate_namessays:rename gives column "Qty" the name order_id, which column "Order ID" loads as too; give each a name of its own
on_duplicate_names
Section titled “on_duplicate_names”Decides what happens when columns meet under one name, ignoring case: a repeated header, or names
that meet after naming (OrderID and Order ID).
| Value | Effect |
|---|---|
number (default) |
The first keeps the name; the others get _1, _2, …, skipping names the table has: qty, qty_1, qty loads as qty, qty_1, qty_2. |
fail |
plan fails, naming the columns. |
columns "OrderID" and "Order ID" both load as order_id; give them names of their own with rename, or set on_duplicate_names = "number"On a new table, a repeated header is numbered by its place, and different source names by
sorting them, so files with columns in another order load the same way: Order ID keeps
order_id, OrderID gets order_id_1.
Once a table exists, its run log keeps each number with its source name, and a newcomer such as
ORDER_ID takes the next free number. A clash on a column no load recorded fails. So does a
numbered column whose source name is gone when another would take it:
└── reason orders: column order_id holds "Order ID" from earlier loads, which the source no longer has, and "ORDER_ID" would now load into it; give "ORDER_ID" a name of its own with rename, or rename it to order_id if it is the same column under a new name--reload numbers the table afresh.
compat
Section titled “compat”compat names the columns a load adds and the child tables unnest makes. dlt uses dlt’s
names, so tables a dlt pipeline loaded can carry on under SQLLoad. It doesn’t change source names;
naming’s default already matches dlt.
| What it holds | compat = "sqlload" (default) |
compat = "dlt" |
|---|---|---|
| The load that wrote the row | _sqlload_load_id |
_dlt_load_id |
| When that load started | _sqlload_loaded_at |
_sqlload_loaded_at (dlt has none) |
| The row’s own id | _sqlload_row_id, with row_id or unnest |
_dlt_id, always |
| A child row’s parent row | _sqlload_parent_id |
_dlt_parent_id |
| A child row’s place in its list, from 0 | _sqlload_list_idx |
_dlt_list_idx |
A child row’s root row, under merge |
_sqlload_root_id |
_dlt_root_id |
Under dlt, row_id = false fails plan. Ids are made as dlt makes them, a merged row’s from its
unique_key as dlt’s upsert merge does. dlt’s own tables (_dlt_loads, _dlt_pipeline_state,
_dlt_version) are not written.
Where SQLLoad still differs from dlt under compat = "dlt":
- Columns whose names meet are numbered; dlt keeps the last value. Two keys of one child item that
meet stop the load, and two tables (
order-items,order_items) stop the plan; give one its ownname. - JSON and NDJSON files default to
flatten = "all"and, on a warehouse,unnest = "all"; a table’s own setting replaces it, and[]turns it off. A flattened key first seen after the sampled rows fails the load, naming its column (customer__vip); pin it incolumns. - Python tables and database JSON columns flatten only with
flatten. - A field only NULL in the sampled rows is a text column; dlt makes none.
- A field in
unnestalways goes to its child table, even when an XML element appears once; dlt keeps a single match as a parent column.