Sources
Sources
Postgres tables, Postgres changes, Snowflake tables and queries, ODBC databases, BigQuery, Databricks and MotherDuck tables and queries (beta), DuckDB files, files in S3 or a folder, Google Sheets, and Python sources: the kinds of source and the settings they share.
A source is where data comes from. SQLLoad has eleven kinds:
kind |
Reads | Tables | Declared in |
|---|---|---|---|
postgres |
Tables of a Postgres database, with binary COPY |
One per matching source table | sqlload.toml |
postgres_cdc |
A Postgres database’s inserts, updates and deletes, from a logical replication slot, after a first snapshot | One per matching source table | sqlload.toml |
snowflake |
Tables and views of a Snowflake database, and query results, unloaded as Parquet | One per matching table, and one per query | sqlload.toml |
odbc |
Tables, views and query results of any database with an ODBC driver, read as Arrow | One per matching table, and one per query | sqlload.toml |
bigquery (beta) |
Tables, views and query results of BigQuery, read as Arrow through the Storage Read API | One per matching table, and one per query | sqlload.toml |
databricks (beta) |
Tables, views and query results of a Databricks SQL warehouse, read as Arrow through the Statement Execution API | One per matching table, and one per query | sqlload.toml |
duckdb |
Tables, views and query results of a DuckDB database file, read as Arrow | One per matching table, and one per query | sqlload.toml |
motherduck (beta) |
Tables, views and query results of a MotherDuck database, read as Arrow through a separate DuckDB 1.5 process | One per matching table, and one per query | sqlload.toml |
files |
Parquet, CSV, JSON or NDJSON files in S3 or a local folder | One per source | sqlload.toml |
google_sheets |
Tabs or ranges of a Google Sheets spreadsheet, typed | One per tab or range | sqlload.toml |
| Python | Whatever a Python function yields: dicts, Arrow data, JSON bytes, HTTP jobs | One per decorated function | Python, under python_paths |
Every source loads into a target: its destination, or the project’s default_target. Settings
that shape tables (write_strategy, unique_key, cursor_column and the rest) can be set on the
source as defaults for all its tables, and per table. See
sqlload.toml for the full list. To set up a source step by
step, see the guides, such as Load Postgres tables,
Capture Postgres changes and Python sources.
Choosing tables
Section titled “Choosing tables”A database source (every kind above except files, google_sheets and Python) loads the tables
that match one of its include patterns and none of its exclude patterns, such as
include = ["sales.*"] (* matches any text). Each kind’s page gives the form of a name.
- A
[sources.<name>.tables."schema.table"]entry sets options for one table. On its own, it doesn’t add the table. - Every table needs a
write_strategy, from its entry or the source, so a new table thatincludematches takes the source’s.unique_key = "{primary_key}"uses each table’s primary key, and failsplanfor a table without one. See Write strategies. - A table’s
description, given to the destination table as its comment, comes from its entry, else from the source table’s own comment (its description on BigQuery). - A source needs at least one
includepattern, or one query table.
new_tables says what happens to a table that matches include after the source’s first load:
new_tables |
A new table |
|---|---|
sync (default) |
Loads like the others. |
skip |
Is left out until include names it exactly, such as include = ["public.*", "public.refunds"]. |
fail |
Stops the plan. |
The first load is the one before any of the source’s tables exists in the destination. A table
that didn’t load then, such as one a problem blocked, counts as new afterwards, so name it exactly
in include.
Query tables
Section titled “Query tables”On Snowflake, ODBC, BigQuery, Databricks, DuckDB and MotherDuck sources, a table entry with sql is
a query table: its rows are the query’s result, and the entry’s key is its name. plan reads the
query’s columns without reading its rows. Its cursor_column names a column of the result:
SQLLoad filters on it outside the query, so the query needs no placeholder.
[sources.shop.tables.big_orders]description = "Orders of 500 or more."sql = """SELECT order_id, customer_id, placed_at, totalFROM shop.orders WHERE total >= 500"""cursor_column = "placed_at"write_strategy = "append"Filtering rows
Section titled “Filtering rows”where narrows a database source’s tables (not postgres_cdc) to the rows that match a condition,
in the source’s own SQL:
[sources.app]where = "tenant_id = 42"
[sources.app.tables."public.orders"]where = "tenant_id = 42 AND status <> 'void'"- SQLLoad ANDs it into every
SELECTit reads the table with: cursor reads,batch_sizewindows,--reload,replace, and the key scan ofload --sync-deletes. The table keeps its primary key, and the database can use its indexes. - On the source, it applies to every table
includematches. A table’s ownwherereplaces it. planruns it on the source, selecting no rows (a dry run on BigQuery), and shows it on afilterline, so a typo failsplan, naming the table.- A query table refuses
where: put the condition in itssql. - A row that later stops matching isn’t removed from a
merge,appendordelete_inserttable.replacedrops it, and so doesdeleteswithload --sync-deletes; see Rows deleted at the source.
Choosing columns
Section titled “Choosing columns”| Setting | Effect |
|---|---|
exclude_columns |
Column patterns to leave out. |
allow_columns |
Column patterns kept even when exclude_columns or skip_tables_with_columns matches them. |
skip_tables_with_columns |
Leave out any table that has a column matching one of these patterns. |
mask (per table) |
Keep a column but replace its values with hash (SHA-256 hex) or hmac (HMAC-SHA256 hex, keyed by the source’s mask_key). |
[sources.app]kind = "postgres"connection = "app"include = ["public.*"]exclude_columns = ["*_at"]allow_columns = ["updated_at"]skip_tables_with_columns = ["total"]mask_key = "${ENV:MASK_KEY}"write_strategy = "replace"
[sources.app.tables."public.customers"]description = "Customers."mask = { email = "hmac" }$ sqlload plan -v…Objects (1) sqlload apply└── raw.app__customers create table ├── customer_id int -> BIGINT ├── email text -> VARCHAR ├── country text -> VARCHAR ├── + _sqlload_load_id, _loaded_at ├── excluded created_at (exclude_columns *_at) └── masked email (hmac)…Skipped (1)└── raw.app__orders └── reason has column total, which matches skip_tables_with_columns…Anyone can recompute a hash, so guessable values such as emails can be recovered: use hmac for
personal data. A masked column can’t be the cursor_column, or part of the unique_key or
replace_key.