Use a DuckDB extension
DuckDB extensions add functions that pipeline SQL can call: geometry from spatial, or typed
judgments from the Jev community extension. This guide lists one in
project.yml, calls it from a pipeline, and prepares a machine with no internet access to run the
same project.
Prerequisites
Section titled “Prerequisites”- A
pzproject that already runs. Follow the quickstart if you don’t have one. - The name of the extension, exactly as you would write it after DuckDB’s
INSTALL.
-
List the extension in
project.yml:project.yml extensions:- jevpz decides whether a name is a core extension or a community one. Before any SQL runs, in every session that runs or validates the project, it runs
INSTALL jev FROM community; LOAD jev;(a core extension gets a plainINSTALL). List only the extensions your SQL calls; the ones connectors and file formats need are loaded by those connectors. -
Call its functions from a pipeline:
-- pipelines/angry_tickets.sqlINSERT INTO {{ sink('lake', 'angry_tickets', strategy: 'replace', format: 'csv') }}select t.id, t.subject, jev_prob(t, 'the customer is angry') as p_angryfrom {{ source('raw', 'tickets') }} twhere jev(t, 'the customer is angry')Don’t write
INSTALLorLOADin a pipeline file: a pipeline is one query. Secrets stay out ofproject.ymltoo. Jev, for instance, reads its key from theTYPESAFE_API_KEYenvironment variable. -
Validate:
Terminal window pz validateThe first run downloads the extension into DuckDB’s extensions folder. A name that cannot be installed or loaded is
PZ0402. A function called from an extension you did not list fails the pre-run SQL check (PZ0401) with a hint to add it underextensions:.
Run on a machine without internet access
Section titled “Run on a machine without internet access”pz never downloads an extension that is already in DuckDB’s extensions folder, so an offline machine needs the files copied there ahead of time:
- Find the folder. It is
~/.duckdb/extensions/<duckdb version>/<platform>/for the user pz runs as, for example~/.duckdb/extensions/v2.0.1/linux_amd64/. The quickest way to get the exact path is to runpz validateonce on that machine: thePZ0402error names it. - Download each file on a machine with internet access, for the same DuckDB version and
platform:
- core:
http://extensions.duckdb.org/<version>/<platform>/<name>.duckdb_extension.gz - community:
http://community-extensions.duckdb.org/<version>/<platform>/<name>.duckdb_extension.gz
- core:
- Unzip and copy each
<name>.duckdb_extensioninto the folder. A few file names differ from the extension name (sqliteissqlite_scanner.duckdb_extension); thePZ0402error names the file it wants. - Copy the connectors’ extensions as well. Connectors that read cloud storage or other
databases install extensions of their own (
httpfsfor S3 and GCS,azurefor Azure Blob,iceberg,sqlite, and so on). The same folder covers them. - Validate again.
pz validatepasses without touching the network.
Each extension file works with one DuckDB version and one platform. After a pz upgrade that moves DuckDB to a new version, copy the files again for the new version.
Things to know
Section titled “Things to know”-
A community extension is built per DuckDB version. After pz moves to a new DuckDB, an extension that has not been built for it yet fails to download (
PZ0402, HTTP 404) until its author publishes that build. On DuckDB 2.0.1 that includes Jev for now. Query.Farm’s extensions (crypto,rapidfuzz,hashfuncs,lindeland others) are published for DuckDB 2.0 from Query.Farm’s own repository, and the builds in the community repository refuse to load. -
An extension runs inside pz. It is native code with access to the run’s data and credentials. A community extension can be published by anyone, so list one only if you trust it.
-
Extensions that call outside services still need the network. Jev sends rows to TypeSafe’s API on every call, so a machine without any internet access cannot use it, however the file got there.
-
Which build ran is recorded. The terminal
run_results.jsonlists each loaded extension and the build DuckDB reports for it, so a behaviour change can be traced to a new extension build.
Related
Section titled “Related”- project.yml reference: the
extensions:key. - Error codes:
PZ0401andPZ0402. - Inspect and validate:
pz validateand the pre-run checks.