pg_math

GSL statistical functions for postgresql

Overview

PackageVersionCategoryLicenseLanguage
pg_math1.1.0FUNCGPL-3.0C
IDExtensionBinLibLoadCreateTrustRelocSchema
4780pg_mathNoYesNoYesNoYes-
Relatedpg_idkit pgx_ulid pg_uuidv7 permuteseq pg_hashids sequential_uuids topn quantile

Version

TypeRepoVersionPG VerPackageDeps
EXTPIGSTY1.1.01817161514pg_math-
RPMPIGSTY1.1.01817161514pg_math_$v-
DEBPIGSTY1.1.01817161514postgresql-$v-pg-math-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64
el8.aarch64
el9.x86_64
el9.aarch64
el10.x86_64
el10.aarch64
d12.x86_64
d12.aarch64
d13.x86_64
d13.aarch64
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
u22.x86_64
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
u22.aarch64
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
u24.x86_64
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
u24.aarch64
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0

Build

You can build the RPM / DEB packages for pg_math using pig build:

pig build pkg pg_math         # build RPM / DEB packages

Install

You can install pg_math directly. First, make sure the PGDG and PIGSTY repositories are added and enabled:

pig repo add pgsql -u          # Add repo and update cache

Install the extension using pig or apt/yum/dnf:

pig install pg_math;          # Install for current active PG version
pig ext install -y pg_math -v 18  # PG 18
pig ext install -y pg_math -v 17  # PG 17
pig ext install -y pg_math -v 16  # PG 16
pig ext install -y pg_math -v 15  # PG 15
pig ext install -y pg_math -v 14  # PG 14
dnf install -y pg_math_18       # PG 18
dnf install -y pg_math_17       # PG 17
dnf install -y pg_math_16       # PG 16
dnf install -y pg_math_15       # PG 15
dnf install -y pg_math_14       # PG 14
apt install -y postgresql-18-pg-math   # PG 18
apt install -y postgresql-17-pg-math   # PG 17
apt install -y postgresql-16-pg-math   # PG 16
apt install -y postgresql-15-pg-math   # PG 15
apt install -y postgresql-14-pg-math   # PG 14

Create Extension:

CREATE EXTENSION pg_math;

Usage

pg_math: statistical distribution functions using GSL for PostgreSQL

Provides CDF (cumulative distribution) and RDF (random distribution) functions for 31 statistical distributions using the GNU Scientific Library (GSL).

CREATE EXTENSION pg_math;

Supported Distributions

Gaussian, Unit Gaussian, Gaussian Tail, Bivariate Gaussian, F-Distribution, Exponential, Laplace, Exponential Power, Cauchy, Rayleigh, Rayleigh Tail, Landau, Gamma, Flat (Uniform), Lognormal, Chi-squared, T-Distribution, Beta, Logistic, Pareto, Weibull, Type-1 Gumbel, Type-2 Gumbel, Poisson, Bernoulli, Binomial, Negative Binomial, Pascal, Geometric, Hypergeometric, Logarithmic.

Function Naming Convention

  • rdf_<distribution>(...) – random distribution function (PDF value)
  • cdf_<distribution>_p(...) – cumulative distribution P-value
  • cdf_<distribution>_q(...) – cumulative distribution Q-value (1-P)
  • cdf_<distribution>_pinv(...) – inverse CDF P
  • cdf_<distribution>_qinv(...) – inverse CDF Q

Examples

-- Gaussian distribution
SELECT rdf_gaussian(1.5, 2.0);            -- PDF at x=1.5, sigma=2.0
SELECT cdf_gaussian_p(1.5, 2.0);          -- CDF P-value

-- Unit Gaussian (standard normal)
SELECT cdf_unit_gaussian_p(1.96);          -- ~0.975

-- Chi-squared distribution
SELECT cdf_chisq_p(3.84, 1.0);            -- ~0.95

-- T-distribution
SELECT cdf_tdist_pinv(0.975, 10.0);       -- critical value for 95% CI with df=10

-- Poisson distribution
SELECT rdf_poisson(5, 3.0);               -- P(X=5) with lambda=3

-- Beta distribution
SELECT rdf_beta(0.5, 2.0, 5.0);           -- PDF at x=0.5, a=2, b=5

Last Modified 2026-03-12: add pg extension catalog (95749bf)