pg_math

pg_math

pg_math : GSL statistical functions for postgresql

Overview

ID Extension Package Version Category License Language
4780
pg_math
pg_math
1.1.0
FUNC
GPL-3.0
C
Attribute Has Binary Has Library Need Load Has DDL Relocatable Trusted
--s-d-r
No
Yes
No
Yes
yes
no
Relationships
See Also
pg_idkit
pgx_ulid
pg_uuidv7
permuteseq
pg_hashids
sequential_uuids
topn
quantile

Packages

Type Repo Version PG Major Compatibility Package Pattern Dependencies
EXT
PIGSTY
1.1.0
18
17
16
15
14
pg_math -
RPM
PIGSTY
1.1.0
18
17
16
15
14
pg_math_$v -
DEB
PIGSTY
1.1.0
18
17
16
15
14
postgresql-$v-pg-math -
Linux / PG PG18 PG17 PG16 PG15 PG14
el8.x86_64
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
el8.aarch64
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
el9.x86_64
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
el9.aarch64
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
el10.x86_64
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
el10.aarch64
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
d12.x86_64
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
d12.aarch64
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
d13.x86_64
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
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
Package Version OS ORG SIZE File URL
pg_math_18 1.1.0 el8.x86_64 pigsty 33.2 KiB pg_math_18-1.1.0-1PIGSTY.el8.x86_64.rpm
pg_math_18 1.1.0 el8.aarch64 pigsty 31.1 KiB pg_math_18-1.1.0-1PIGSTY.el8.aarch64.rpm
pg_math_18 1.1.0 el9.x86_64 pigsty 31.0 KiB pg_math_18-1.1.0-1PIGSTY.el9.x86_64.rpm
pg_math_18 1.1.0 el9.aarch64 pigsty 29.8 KiB pg_math_18-1.1.0-1PIGSTY.el9.aarch64.rpm
pg_math_18 1.1.0 el10.x86_64 pigsty 31.3 KiB pg_math_18-1.1.0-1PIGSTY.el10.x86_64.rpm
pg_math_18 1.1.0 el10.aarch64 pigsty 30.2 KiB pg_math_18-1.1.0-1PIGSTY.el10.aarch64.rpm
postgresql-18-pg-math 1.1.0 d12.x86_64 pigsty 60.7 KiB postgresql-18-pg-math_1.1.0-1PIGSTY~bookworm_amd64.deb
postgresql-18-pg-math 1.1.0 d12.aarch64 pigsty 59.7 KiB postgresql-18-pg-math_1.1.0-1PIGSTY~bookworm_arm64.deb
postgresql-18-pg-math 1.1.0 d13.x86_64 pigsty 60.7 KiB postgresql-18-pg-math_1.1.0-1PIGSTY~trixie_amd64.deb
postgresql-18-pg-math 1.1.0 d13.aarch64 pigsty 60.1 KiB postgresql-18-pg-math_1.1.0-1PIGSTY~trixie_arm64.deb
postgresql-18-pg-math 1.1.0 u22.x86_64 pigsty 68.1 KiB postgresql-18-pg-math_1.1.0-1PIGSTY~jammy_amd64.deb
postgresql-18-pg-math 1.1.0 u22.aarch64 pigsty 67.0 KiB postgresql-18-pg-math_1.1.0-1PIGSTY~jammy_arm64.deb
postgresql-18-pg-math 1.1.0 u24.x86_64 pigsty 64.9 KiB postgresql-18-pg-math_1.1.0-1PIGSTY~noble_amd64.deb
postgresql-18-pg-math 1.1.0 u24.aarch64 pigsty 63.8 KiB postgresql-18-pg-math_1.1.0-1PIGSTY~noble_arm64.deb
Package Version OS ORG SIZE File URL
pg_math_17 1.1.0 el8.x86_64 pigsty 33.2 KiB pg_math_17-1.1.0-1PIGSTY.el8.x86_64.rpm
pg_math_17 1.1.0 el8.aarch64 pigsty 31.2 KiB pg_math_17-1.1.0-1PIGSTY.el8.aarch64.rpm
pg_math_17 1.1.0 el9.x86_64 pigsty 31.0 KiB pg_math_17-1.1.0-1PIGSTY.el9.x86_64.rpm
pg_math_17 1.1.0 el9.aarch64 pigsty 29.8 KiB pg_math_17-1.1.0-1PIGSTY.el9.aarch64.rpm
pg_math_17 1.1.0 el10.x86_64 pigsty 31.3 KiB pg_math_17-1.1.0-1PIGSTY.el10.x86_64.rpm
pg_math_17 1.1.0 el10.aarch64 pigsty 30.1 KiB pg_math_17-1.1.0-1PIGSTY.el10.aarch64.rpm
postgresql-17-pg-math 1.1.0 d12.x86_64 pigsty 60.9 KiB postgresql-17-pg-math_1.1.0-1PIGSTY~bookworm_amd64.deb
postgresql-17-pg-math 1.1.0 d12.aarch64 pigsty 59.8 KiB postgresql-17-pg-math_1.1.0-1PIGSTY~bookworm_arm64.deb
postgresql-17-pg-math 1.1.0 d13.x86_64 pigsty 60.4 KiB postgresql-17-pg-math_1.1.0-1PIGSTY~trixie_amd64.deb
postgresql-17-pg-math 1.1.0 d13.aarch64 pigsty 60.1 KiB postgresql-17-pg-math_1.1.0-1PIGSTY~trixie_arm64.deb
postgresql-17-pg-math 1.1.0 u22.x86_64 pigsty 68.8 KiB postgresql-17-pg-math_1.1.0-1PIGSTY~jammy_amd64.deb
postgresql-17-pg-math 1.1.0 u22.aarch64 pigsty 67.8 KiB postgresql-17-pg-math_1.1.0-1PIGSTY~jammy_arm64.deb
postgresql-17-pg-math 1.1.0 u24.x86_64 pigsty 64.8 KiB postgresql-17-pg-math_1.1.0-1PIGSTY~noble_amd64.deb
postgresql-17-pg-math 1.1.0 u24.aarch64 pigsty 63.7 KiB postgresql-17-pg-math_1.1.0-1PIGSTY~noble_arm64.deb
Package Version OS ORG SIZE File URL
pg_math_16 1.1.0 el8.x86_64 pigsty 33.2 KiB pg_math_16-1.1.0-1PIGSTY.el8.x86_64.rpm
pg_math_16 1.1.0 el8.aarch64 pigsty 31.2 KiB pg_math_16-1.1.0-1PIGSTY.el8.aarch64.rpm
pg_math_16 1.1.0 el9.x86_64 pigsty 31.3 KiB pg_math_16-1.1.0-1PIGSTY.el9.x86_64.rpm
pg_math_16 1.1.0 el9.aarch64 pigsty 29.8 KiB pg_math_16-1.1.0-1PIGSTY.el9.aarch64.rpm
pg_math_16 1.1.0 el10.x86_64 pigsty 31.3 KiB pg_math_16-1.1.0-1PIGSTY.el10.x86_64.rpm
pg_math_16 1.1.0 el10.aarch64 pigsty 30.1 KiB pg_math_16-1.1.0-1PIGSTY.el10.aarch64.rpm
postgresql-16-pg-math 1.1.0 d12.x86_64 pigsty 60.7 KiB postgresql-16-pg-math_1.1.0-1PIGSTY~bookworm_amd64.deb
postgresql-16-pg-math 1.1.0 d12.aarch64 pigsty 59.9 KiB postgresql-16-pg-math_1.1.0-1PIGSTY~bookworm_arm64.deb
postgresql-16-pg-math 1.1.0 d13.x86_64 pigsty 60.7 KiB postgresql-16-pg-math_1.1.0-1PIGSTY~trixie_amd64.deb
postgresql-16-pg-math 1.1.0 d13.aarch64 pigsty 60.0 KiB postgresql-16-pg-math_1.1.0-1PIGSTY~trixie_arm64.deb
postgresql-16-pg-math 1.1.0 u22.x86_64 pigsty 68.8 KiB postgresql-16-pg-math_1.1.0-1PIGSTY~jammy_amd64.deb
postgresql-16-pg-math 1.1.0 u22.aarch64 pigsty 67.8 KiB postgresql-16-pg-math_1.1.0-1PIGSTY~jammy_arm64.deb
postgresql-16-pg-math 1.1.0 u24.x86_64 pigsty 64.8 KiB postgresql-16-pg-math_1.1.0-1PIGSTY~noble_amd64.deb
postgresql-16-pg-math 1.1.0 u24.aarch64 pigsty 63.7 KiB postgresql-16-pg-math_1.1.0-1PIGSTY~noble_arm64.deb
Package Version OS ORG SIZE File URL
pg_math_15 1.1.0 el8.x86_64 pigsty 33.2 KiB pg_math_15-1.1.0-1PIGSTY.el8.x86_64.rpm
pg_math_15 1.1.0 el8.aarch64 pigsty 31.2 KiB pg_math_15-1.1.0-1PIGSTY.el8.aarch64.rpm
pg_math_15 1.1.0 el9.x86_64 pigsty 31.0 KiB pg_math_15-1.1.0-1PIGSTY.el9.x86_64.rpm
pg_math_15 1.1.0 el9.aarch64 pigsty 29.8 KiB pg_math_15-1.1.0-1PIGSTY.el9.aarch64.rpm
pg_math_15 1.1.0 el10.x86_64 pigsty 31.3 KiB pg_math_15-1.1.0-1PIGSTY.el10.x86_64.rpm
pg_math_15 1.1.0 el10.aarch64 pigsty 30.0 KiB pg_math_15-1.1.0-1PIGSTY.el10.aarch64.rpm
postgresql-15-pg-math 1.1.0 d12.x86_64 pigsty 60.9 KiB postgresql-15-pg-math_1.1.0-1PIGSTY~bookworm_amd64.deb
postgresql-15-pg-math 1.1.0 d12.aarch64 pigsty 59.9 KiB postgresql-15-pg-math_1.1.0-1PIGSTY~bookworm_arm64.deb
postgresql-15-pg-math 1.1.0 d13.x86_64 pigsty 60.6 KiB postgresql-15-pg-math_1.1.0-1PIGSTY~trixie_amd64.deb
postgresql-15-pg-math 1.1.0 d13.aarch64 pigsty 60.2 KiB postgresql-15-pg-math_1.1.0-1PIGSTY~trixie_arm64.deb
postgresql-15-pg-math 1.1.0 u22.x86_64 pigsty 68.8 KiB postgresql-15-pg-math_1.1.0-1PIGSTY~jammy_amd64.deb
postgresql-15-pg-math 1.1.0 u22.aarch64 pigsty 67.8 KiB postgresql-15-pg-math_1.1.0-1PIGSTY~jammy_arm64.deb
postgresql-15-pg-math 1.1.0 u24.x86_64 pigsty 64.8 KiB postgresql-15-pg-math_1.1.0-1PIGSTY~noble_amd64.deb
postgresql-15-pg-math 1.1.0 u24.aarch64 pigsty 63.7 KiB postgresql-15-pg-math_1.1.0-1PIGSTY~noble_arm64.deb
Package Version OS ORG SIZE File URL
pg_math_14 1.1.0 el8.x86_64 pigsty 33.2 KiB pg_math_14-1.1.0-1PIGSTY.el8.x86_64.rpm
pg_math_14 1.1.0 el8.aarch64 pigsty 31.1 KiB pg_math_14-1.1.0-1PIGSTY.el8.aarch64.rpm
pg_math_14 1.1.0 el9.x86_64 pigsty 31.3 KiB pg_math_14-1.1.0-1PIGSTY.el9.x86_64.rpm
pg_math_14 1.1.0 el9.aarch64 pigsty 29.8 KiB pg_math_14-1.1.0-1PIGSTY.el9.aarch64.rpm
pg_math_14 1.1.0 el10.x86_64 pigsty 31.3 KiB pg_math_14-1.1.0-1PIGSTY.el10.x86_64.rpm
pg_math_14 1.1.0 el10.aarch64 pigsty 30.1 KiB pg_math_14-1.1.0-1PIGSTY.el10.aarch64.rpm
postgresql-14-pg-math 1.1.0 d12.x86_64 pigsty 60.6 KiB postgresql-14-pg-math_1.1.0-1PIGSTY~bookworm_amd64.deb
postgresql-14-pg-math 1.1.0 d12.aarch64 pigsty 59.7 KiB postgresql-14-pg-math_1.1.0-1PIGSTY~bookworm_arm64.deb
postgresql-14-pg-math 1.1.0 d13.x86_64 pigsty 60.5 KiB postgresql-14-pg-math_1.1.0-1PIGSTY~trixie_amd64.deb
postgresql-14-pg-math 1.1.0 d13.aarch64 pigsty 60.0 KiB postgresql-14-pg-math_1.1.0-1PIGSTY~trixie_arm64.deb
postgresql-14-pg-math 1.1.0 u22.x86_64 pigsty 68.7 KiB postgresql-14-pg-math_1.1.0-1PIGSTY~jammy_amd64.deb
postgresql-14-pg-math 1.1.0 u22.aarch64 pigsty 67.5 KiB postgresql-14-pg-math_1.1.0-1PIGSTY~jammy_arm64.deb
postgresql-14-pg-math 1.1.0 u24.x86_64 pigsty 64.8 KiB postgresql-14-pg-math_1.1.0-1PIGSTY~noble_amd64.deb
postgresql-14-pg-math 1.1.0 u24.aarch64 pigsty 63.7 KiB postgresql-14-pg-math_1.1.0-1PIGSTY~noble_arm64.deb

Source

pig build pkg pg_math;		# build rpm/deb

Install

Make sure PGDG and PIGSTY repo available:

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

Install this extension with pig:

pig install pg_math;		# install via package name, for the active PG version

pig install pg_math -v 18;   # install for PG 18
pig install pg_math -v 17;   # install for PG 17
pig install pg_math -v 16;   # install for PG 16
pig install pg_math -v 15;   # install for PG 15
pig install pg_math -v 14;   # install for PG 14

Create this extension with:

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 updated on