Skip to content

Concepts

Contracts and schema changes

Where a table's columns come from, what happens when the source changes, and how declared columns are checked against live tables.

SQLLoad keeps no copy of your schema. Each run reads the destination table’s columns and compares them with the source, or with the columns you declare. plan shows any change before anything runs.

contract Source of truth Behaviour
none (default) The live table The first load creates the table from the source’s types. Later runs follow the table, including changes made by hand.
enforced Columns declared in columns Source columns not declared aren’t loaded, and plan warns about them.

Most tables mix both: pin a few columns and let the rest follow the source. Types use SQLLoad’s portable names, such as int, decimal(18,2) or timestamp_tz; see Types.

[sources.app.tables."public.orders"]
description = "Orders, one row per order."
write_strategy = "merge"
unique_key = "{primary_key}"
cursor_column = "updated_at"
columns = { total = "decimal(18,2)" }
on_schema_change A new source column
append_new_columns (default) Is added to the table.
ignore Is left out.
fail Stops the table.
$ sqlload plan -v app__orders
Plan ready 1 selected, 1 to alter, 1 to load
Objects (1) sqlload apply
└── raw.app__orders alter table
└── add column coupon text -> VARCHAR

SQLLoad never drops columns from a destination table.

On a files or Python table, a declared column the data doesn’t hold loads as NULL at its declared type, with a warning; on_schema_change = "fail" stops the table instead. A name close to one the data holds, such as Email for email, fails as a likely typo.

$ sqlload plan orders
…
Warnings (1)
└── orders
└── declared column coupon is in none of the sampled files, so rows without it load as NULL

A files table looks in the files plan samples, so a column only older files hold loads where they hold it, but fails under fail. A Python table is checked once it has yielded every row: under fail, a replace keeps its old rows, and an append keeps what earlier commits loaded. plan --json and load --json list the columns under missing_columns.

A pinned type wider than the live column widens it:

$ sqlload plan -v app__orders
…
└── raw.app__orders alter table
└── widen total decimal(12,2) -> decimal(18,2) (DECIMAL(18,2)) in place

The pin must hold every value already in the column, as the column widens to exactly the pin:

$ sqlload plan app__orders
…
└── reason total is decimal(14,4) in the table but pinned as decimal(14,2), which does not hold every decimal(14,4); pin decimal(16,4) to widen it (columns = { total = "decimal(16,4)" })

A load never narrows a column. A narrower pin fails plan; --reload rebuilds the table at the pinned type, and fails without changing it if a value doesn’t fit. A Postgres target or a postgres_cdc table is never rebuilt, so alter the column yourself.

$ sqlload plan app__orders
…
└── reason total is decimal(14,4) in the table but pinned as decimal(12,2), and a load never narrows a column; pin the table's type (columns = { total = "decimal(14,4)" }), or rebuild the table at the pinned type with --reload

A type the source can’t be read as fails plan too: total has type numeric(12,2), which cannot be read as int.

A column whose type SQLLoad infers (Python tables, CSV and JSON files) doesn’t change type on its own. When values outgrow it, the table fails with the column, both types and the fix. With auto_widen = true on the table or source, it widens along bool → int → decimal and timestamp_ntz → timestamp_tz instead. It never widens to float, text or json: pin those, or set infer_types = false to load every inferred column as text (Loading every column as text).

Some warehouses can’t change a type in place: Snowflake can’t turn NUMBER(38,0) into NUMBER(18,2). Such a change rebuilds the table and swaps it in, keeping grants.

type_change_rebuild A rebuild
require_confirmation (default) Needs --allow-type-change-rebuild.
allow Runs.
deny Stops the table.

Only the affected table stops; the others load.

sqlload contract diff compares each table’s declared columns with its live table, and changes nothing. It exits 1 when anything differs, so it fits in CI. On contract = "enforced" tables it also reports live columns nothing declares.

$ sqlload contract diff
Contract comparison
OK table:app__customers
DIFF table:app__orders
type_mismatch: column 'total' is declared decimal(18,2) but physical type is decimal(12,2)
1 contract difference(s)

sqlload contract generate prints the declarations that match each live table, and --write writes them into sqlload.toml, keeping the rest of the file. Use it to adopt an existing table or to move one to contract = "enforced". See sqlload contract.