Install and load
Prerequisites
- DuckDB version 1.3 or newer (the CLI, the app, or any language client).
Install from the community repository
Once the extension is registered in DuckDB's community extensions, installing is two statements:
INSTALL duckfn_statrs FROM community;
LOAD duckfn_statrs;
No extra flags needed — the community build is signed and matches your DuckDB version.
Install from a GitHub Release
If the community route is not yet available for your platform, download the pre-built binary from the
releases page. The asset is named
duckfn_statrs-<platform>.duckdb_extension and has to be renamed to duckfn_statrs.duckdb_extension before it
can be loaded: LOAD takes an extension name or a local path — it fetches no URLs (INSTALL '<url>' is the
one that downloads) — and DuckDB takes the entry-point symbol from the file name, so the release name fails with
did not contain function "duckfn_statrs-windows_amd64_init_c_api":
curl -LO https://github.com/shijianjs/duckfn-statrs/releases/latest/download/duckfn_statrs-windows_amd64.duckdb_extension
mv duckfn_statrs-windows_amd64.duckdb_extension duckfn_statrs.duckdb_extension
duckdb -unsigned -c "LOAD './duckfn_statrs.duckdb_extension';"
Released binaries are not signed by DuckDB's distribution key, so start the CLI with the -unsigned
flag: duckdb -unsigned. The community route above does not have this limitation.
Verify the installation
SELECT function_name, function_type
FROM duckdb_functions()
WHERE function_name LIKE 'sr_%'
ORDER BY function_name;
-- 511 rows
First queries
Summary statistics are aggregates — pass a column, get one value per group:
SELECT g, sr_mean(x) AS mean, sr_std_dev(x) AS std_dev, sr_median(x) AS median
FROM (VALUES (1, 1.0), (1, 2.0), (1, 3.0), (2, 10.0), (2, 20.0), (2, NULL)) t(g, x)
GROUP BY g
ORDER BY g;
Distribution functions are scalars — evaluated row by row:
SELECT x, sr_normal_cdf(x, 0.0, 1.0) AS cdf, sr_normal_pdf(x, 0.0, 1.0) AS pdf
FROM (VALUES (-1.96::DOUBLE), (0.0), (1.96)) t(x);
Errors on invalid parameters are clear and specific:
SELECT sr_normal_pdf(0.0, 0.0, -1.0); -- error: sr_normal_pdf: Standard deviation is NaN, zero or less than zero
NULL behaviour
- NULL input rows never enter an aggregate (standard SQL convention).
- When statrs cannot define a result (empty group, insufficient samples, out-of-range parameter), the return value is SQL NULL — never NAN.
- A parameter that is present but invalid (e.g.
std_dev <= 0) raises a query error.
-- statrs cannot define the sample variance of one value: the result is NULL, not 0.
SELECT grp, sr_variance(x) AS variance
FROM (VALUES ('two', 1.5::DOUBLE), ('two', 2.5), ('one', NULL::DOUBLE), ('one', 3.0)) t(grp, x)
GROUP BY grp
ORDER BY grp;
What to do next
- Browse the full function reference organized by category.
- Need to build from source or contribute? See the development guide.