pg_math
Overview
| Package | Version | Category | License | Language |
|---|---|---|---|---|
pg_math | 1.1.0 | FUNC | GPL-3.0 | C |
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 4780 | pg_math | No | Yes | No | Yes | No | Yes | - |
| Related | pg_idkit pgx_ulid pg_uuidv7 permuteseq pg_hashids sequential_uuids topn quantile |
|---|
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | PIGSTY | 1.1.0 | 1817161514 | pg_math | - |
| RPM | PIGSTY | 1.1.0 | 1817161514 | pg_math_$v | - |
| DEB | PIGSTY | 1.1.0 | 1817161514 | postgresql-$v-pg-math | - |
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-valuecdf_<distribution>_q(...)– cumulative distribution Q-value (1-P)cdf_<distribution>_pinv(...)– inverse CDF Pcdf_<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
Feedback
Was this page helpful?
Thanks for the feedback! Please let us know how we can improve.
Sorry to hear that. Please let us know how we can improve.