Skip to content

Concepts

Projects

How connections, targets and sources fit together in sqlload.toml, and how plan, apply and load use them.

A project is a sqlload.toml file with three kinds of entry:

Entry Says Example
[connections.NAME] How to reach one system: a database, a warehouse, a bucket, a folder or an HTTP API. kind = "postgres", host, user, password
[targets.NAME] Where loaded tables go: a warehouse connection and schema, or a files connection and folder layout. connection = "warehouse", loader_schema = "raw"
[sources.NAME] Where data comes from, which tables it has, and how they load. kind = "postgres", include = ["public.*"]
default_target = "local"
[connections.app]
kind = "postgres"
host = "localhost"
user = "postgres"
password = "${ENV:PGPASSWORD}"
database = "postgres"
[connections.warehouse]
kind = "duckdb"
database = "shop.duckdb"
[targets.local]
connection = "warehouse"
loader_schema = "raw"
[sources.app]
kind = "postgres"
connection = "app"
description = "The shop's application database."
include = ["public.*"]
write_strategy = "merge"
unique_key = "{primary_key}"

Secrets come from the environment through ${ENV:NAME}. Python sources are declared in Python, in the folders python_paths lists, and their tables’ settings live in the decorator. See Load from Python and HTTP APIs.

Command Does
sqlload plan Reads the sources’ and destinations’ catalogs and prints what apply and load would do. Changes nothing.
sqlload apply Creates or changes destination tables, as the plan shows, such as to grant access before data arrives. Never loads data.
sqlload load Loads the selected tables. Creates any table that doesn’t exist yet.

apply and load plan first. One broken table doesn’t stop the others: a table under Errors is left out, a table whose load fails gets a failed line, the rest still load, and the command exits 1.

plan, apply, load and contract take selectors, positionally or with --select/-s, and --exclude. A selector is a source name, a destination table name, or a source’s schema.table. With none, every table is selected:

sqlload load app # every table of source app
sqlload load app__orders # one destination table
sqlload load public.orders # the same table, by its source name
sqlload load app --exclude app__customers

A source’s problem, such as a refused setting, an unreachable server or an invalid include pattern, fails only commands that select from it. A bare sqlload load loads the other sources, lists the problem under Errors, and exits 1, or 75 when every problem may pass on a rerun, such as an unreachable server. fix names the ${ENV:NAME} variables the connection reads:

$ sqlload load
Errors (1)
└── billing can't connect
├── reason cannot connect to Postgres at localhost:5499/postgres: error connecting to server:
│ Connection refused (os error 111)
├── fix check BILLING_PASSWORD (connection billing); sqlload debug tests every connection
└── blocks any table its include patterns match
…

Destination tables are named from a template with {source}, {schema} and {table}:

Source Default name Example
Postgres {source}__{table} app__orders
Python {source}__{table} shop__orders
Files {source} (a files source is one table) events

Set table_name on the source, or name on one table, to change it. Tables go into the source’s destination_schema, else the target’s loader_schema.

A table’s optional description becomes the destination table’s comment.

Table Description from
A Postgres table description = "..." in its [sources.app.tables."public.orders"] entry, or else the source table’s comment (COMMENT ON TABLE)
A files source The source’s own description
A Python table description="...", or the function’s docstring

Every loaded table gets columns that say where each row came from, after its own columns:

Column On Holds
_sqlload_load_id every table The load that wrote the row.
_sqlload_loaded_at every table When that load ran.
_sqlload_source_file files sources The file the row came from.
_sqlload_source_version files sources The file’s version when it was loaded.
_sqlload_source_row files sources The row’s number in its file, from 1. On BigQuery it makes SQLLoad read the files; exclude it to let BigQuery load them.
_sqlload_source_row Google Sheets tables The sheet’s row number: a range from A3 starts at 3, and a skipped empty row leaves a gap. Not with a transform.

A column that first appears after the table exists, such as on a later run, is added after SQLLoad’s columns; sqlload load --reload rebuilds the table with SQLLoad’s columns last. plan lists them as + _sqlload_load_id, _loaded_at. Files sources use _sqlload_source_file to load each file once under append. sqlload contract ignores them.

Up to concurrency tables (in sqlload.toml, or --concurrency N; 4 by default) load at once. One table’s batches commit one at a time.

Nothing outside your destination: no local state folder and no stored schema.

  • Schema: read from the destination table each run, or from the columns you declare. See Contracts.
  • Position: the destination’s maximum of the table’s cursor_column. See Cursors.
  • Logged state, for tables with state = "logged": an append-only run log in the destination. Deleting it is safe; the next run reads as a stateless one would.