Skip to content

Sources

DuckDB

Load tables, views and query results from a DuckDB database file, read as Arrow from a read-only connection: connections, choosing tables, query tables, cursors, types and memory.

A duckdb source loads tables, views and query results from a DuckDB database file. SQLLoad opens the file read-only and streams the result of one SELECT per read as Arrow, so it never writes to the file.

[connections.shop_file]
kind = "duckdb"
database = "shop.duckdb"
[sources.shop]
kind = "duckdb"
connection = "shop_file"
description = "Tables of the shop's DuckDB file."
include = ["sales.*"]
exclude = ["sales.tmp_*"]
write_strategy = "replace"
[sources.shop.tables."sales.orders"]
description = "Orders, one row each."
cursor_column = "updated_at"
write_strategy = "merge"
unique_key = "{primary_key}"
[sources.shop.tables.big_orders]
description = "Orders over 100, with their customer."
sql = """
SELECT o.*, c.name
FROM sales.orders o JOIN sales.customers c USING (customer_id)
WHERE o.amount > 100
"""
cursor_column = "updated_at"
write_strategy = "append"

A source uses a duckdb connection, the same kind a DuckDB target uses, whose database is the file to read. An in-memory database (:memory:) and a MotherDuck database (md:) are refused; use a MotherDuck source for the latter.

DuckDB lets one process write a file, or any number read it. While another process has the file open for writing, a read fails, naming the lock; run the load when the writer has closed it.

include and exclude are schema.table patterns, matched against the names as DuckDB keeps them, such as sales.* or main.orders. Query tables, where and column settings work as for every database source; see Sources. Write where and sql in DuckDB SQL.

Each read is one SELECT of the read columns, with the cursor window and any where, and sees one version of the file. Each read’s DuckDB memory_limit is half the table’s share of the memory budget.

DuckDB type Loads as
TINYINT, SMALLINT, UTINYINT smallint
INTEGER, BIGINT, USMALLINT, UINTEGER int
DECIMAL(p,s), p up to 38 decimal(p,s)
FLOAT, DOUBLE float
BOOLEAN bool
VARCHAR, ENUM text
BLOB binary
DATE date
TIME time
TIMESTAMP, TIMESTAMP_S, TIMESTAMP_MS timestamp_ntz
TIMESTAMP WITH TIME ZONE timestamp_tz
UUID uuid
JSON, lists, arrays, STRUCT, MAP json
HUGEINT, UBIGINT, TIMESTAMP_NS, INTERVAL, BIT, UNION and others none: pin a type such as text, or exclude the column

Pin a type to load a column another way, such as columns = { total = "text" }, or a list as array(T); a value that doesn’t convert fails the read, naming the column. See Types.