Targets
MotherDuck
Load into MotherDuck (beta) through a separate DuckDB 1.5 process, with the same SQL and write strategies as DuckDB.
This target is in beta: it is tested, but gets less everyday use than the other connectors, so expect rough edges, and please report them in GitHub issues.
A MotherDuck target loads into a MotherDuck database with the same SQL, types and write strategies
as a DuckDB target, including
deletes and deletes_from.
Install
Section titled “Install”SQLLoad bundles DuckDB 2.0, which MotherDuck doesn’t accept: it supports DuckDB 1.4.1 to 1.5.6
(duckdb-versions.json). So SQLLoad sends a
MotherDuck target’s SQL to a separate Python process running Python’s duckdb package. Every other
target uses SQLLoad’s own DuckDB.
Install the motherduck extra, which adds duckdb>=1.4.1,<=1.5.6, and pyarrow, which a
MotherDuck source reads through:
uv tool install 'sqlload[motherduck]'# or, in a virtual environmentpip install 'sqlload[motherduck]'Any command that connects to MotherDuck starts the process on the first of these Pythons, and it exits when SQLLoad does, even when SQLLoad is killed:
- The one
SQLLOAD_MOTHERDUCK_PYTHONnames. Set it forsqlload-cli, or to use another Python. - With the
sqlloadcommand of the Python package, that package’s own Python. - Otherwise,
python3onPATH(pythonon Windows).
If the Python can’t run, lacks duckdb, or has a version MotherDuck refuses, sqlload debug,
plan and load say so and how to fix it:
$ sqlload debugfail target shop MotherDuck: cannot open md:shop: MotherDuck doesn't accept the version of Python's duckdb package that SQLLoad connects through: install duckdb 1.4.1 to 1.5.6 there (pip install 'sqlload[motherduck]'), or set SQLLOAD_MOTHERDUCK_PYTHON to a Python that has it. MotherDuck says: Your DuckDB version (v2.0.0) is not yet supported by MotherDuck. …Connection
Section titled “Connection”[connections.shop]kind = "motherduck"database = "shop"token = "${ENV:MOTHERDUCK_TOKEN}"
[targets.shop]connection = "shop"loader_schema = "raw"| Key | Meaning |
|---|---|
database |
The MotherDuck database, with or without md:. Required, here or in the target. It can’t hold the token. |
token |
A MotherDuck access token. Use ${ENV:NAME}. Default: the motherduck_token or MOTHERDUCK_TOKEN environment variable. |
load_method |
How rows reach MotherDuck: { type = "local" } (default) or { type = "external_stage", … }. See Staging in a bucket. |
A target’s database overrides the connection’s, so one connection can serve a shop_dev and a
shop database. The database must exist. Without a token SQLLoad refuses the connection rather
than wait for MotherDuck’s browser sign-in; the token never appears in a command line or an error.
A duckdb connection refuses an md: path; use kind = "motherduck". The first connection
installs MotherDuck’s DuckDB extension into ~/.duckdb, which needs the network once.
How data arrives
Section titled “How data arrives”SQLLoad writes the rows to temporary zstd Parquet files of about 122,880 rows, however small the
source’s pages, and MotherDuck loads each with COPY. plan names the route for every table:
$ sqlload plan -v… ├── route read as Arrow -> zstd Parquet, about 122,880 rows a file -> MotherDuck COPYA load that stops partway commits no part of its open batch; the next load picks up from the
table’s committed rows. Under a memory budget, an append creates
an empty _sqlload_unfinished table beside _sqlload_runs; if an append stops partway, the next
load of that table uses it to remove that append’s rows, and warns.
Staging in a bucket
Section titled “Staging in a bucket”With load_method = { type = "external_stage", … }, SQLLoad uploads the files under an S3 or GCS
prefix instead, and MotherDuck’s servers read them there. It suits a slow or flaky uplink to
MotherDuck, a machine beside the bucket, or keeping the loaded files as an archive.
[connections.shop]kind = "motherduck"database = "shop"load_method.type = "external_stage"load_method.url = "s3://example-bucket/motherduck/"| Key | Meaning |
|---|---|
url |
The prefix, s3://bucket/prefix/ or gs://bucket/prefix/. Files go in a folder named for the load id, then one for the table. |
connection |
An s3 or gcs connection to the bucket, for its region, profile and keys. Required for gs://: MotherDuck reads GCS only with the connection’s HMAC key. Without it, S3 keys come from the environment, the shared credentials file or the AWS credential chain. |
keep_staged_files |
Keep each file once MotherDuck has read it. Default false. A batch that fails before MotherDuck reads it removes its files; a merge or other staged write that fails at its commit keeps them. |
MotherDuck reads with the same keys, as a secret that lasts only for the load’s session. plan
has MotherDuck read a one-row test file and fails each table with the fix when it can’t; it never
falls back to sending from this machine. A custom S3 endpoint is refused. A killed load leaves its
files under its load id; add a lifecycle rule on the prefix to remove them.
$ sqlload plan -v… ├── route read as Arrow -> zstd Parquet, about 122,880 rows a file -> s3://example-bucket/motherduck/ -> MotherDuck reads them on its serversParquet files in S3
Section titled “Parquet files in S3”Parquet files of a files source in S3 load straight from the bucket: MotherDuck’s servers read them, and no row passes through this machine.
$ sqlload plan… └── route DuckDB reads directly from s3://example-bucket/events/ (nothing through the loader)MotherDuck reads with a session-only secret made from the keys SQLLoad finds for the
s3 connection; nothing is stored in your account. A secret of your own
in MotherDuck scoped to a narrower path, such as s3://example-bucket/events/, wins over it. plan
checks MotherDuck can read the first file. MotherDuck reads from its own network, so a bucket whose policy allows only your network or VPC endpoint can’t load
this way, and the keys need kms:Decrypt on a bucket’s KMS key.
Parquet files in GCS
Section titled “Parquet files in GCS”Parquet files in a gcs connection with an HMAC key (hmac_key_id and
hmac_secret) load the same way; without one, SQLLoad reads the files. The key’s service account
needs roles/storage.objectViewer on the bucket, and a VPC Service Controls perimeter around the
bucket keeps MotherDuck out.
SQLLoad reads the files itself for the same reasons as on DuckDB, such as CSV or JSON files, masked columns or a custom S3 endpoint, and for files in a local folder, over SFTP, or unloaded by a Snowflake source. On every route, a batch fails unless MotherDuck loads as many rows as the files’ footers hold.
VARIANT columns
Section titled “VARIANT columns”json_type = "variant" loads json columns as VARIANT, as on
DuckDB. It needs Python’s duckdb 1.5 or later; on 1.4,
plan fails the table with the fix. MotherDuck runs DuckDB 1.5, which stores VARIANT unshredded,
so plan and load warn on each such table, without changing the exit code:
Warnings (1)└── cloud__customers └── MotherDuck runs DuckDB 1.5, which stores VARIANT unshredded: queries on its fields can be much slower than on JSON until MotherDuck moves to DuckDB 2.0; json_type = "json" keeps JSONThe warning goes once MotherDuck’s md_version() reports DuckDB 2.0, or, when it reports none, by
the separate process’s duckdb.
Tested
Section titled “Tested”- Live, on MotherDuck with DuckDB 1.5.6: every write strategy, incremental loads and reruns, a new
column, every portable type and
json_type = "variant"; and Parquet in S3 read on MotherDuck’s servers, compared row for row with the same files read by SQLLoad. - Offline, on every change: every write strategy and portable type through the separate process into a stand-in for MotherDuck, compared with DuckDB, including the process ending mid-load and the setup errors.