Skip to main content

Statistics in plain SQL

511 functions backed by the Rust statrs library, callable directly from your DuckDB queries. Aggregates for summary statistics, scalars for distributions and special functions.

DuckDB SQL
-- Install once, then LOAD in every session:
INSTALL duckfn_statrs FROM community;
LOAD duckfn_statrs;

-- Aggregates: one column in, one value out per group:
SELECT g, sr_mean(x) AS mean, sr_std_dev(x) AS sd
FROM my_table GROUP BY g;

-- Scalars: distribution functions evaluated row by row:
SELECT sr_normal_pdf(0.0, 0.0, 1.0); -- 0.3989...
SELECT sr_gamma_cdf(2.0, 3.0, 2.0); -- 0.4564...

-- NULL semantics: statrs cannot define it → SQL NULL
SELECT sr_variance(x) FROM (VALUES (1.0)) t(x); -- NULL (single value)

Browse all functions