跳转到主要内容

pg_math

使用GSL库的数学统计函数

pg_math · 使用GSL库的数学统计函数

概览

ID扩展软件包版本类别许可证编程语言
4790pg_mathpg_math1.1.0FUNCMITC
属性可执行文件动态库需要预加载需要建扩展可迁移可信
--s-d-r否是否是是否

软件包

类型仓库版本兼容的 PostgreSQL 大版本包名模式依赖
EXTPIGSTY1.1.019 18 17 16 15pg_math-
RPMPIGSTY1.1.019 18 17 16 15pg_math_$v-
DEBPIGSTY1.1.019 18 17 16 15postgresql-$v-pg-math-
Linux / PGPG19PG18PG17PG16PG15
el8.x86_64N/APIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0
el8.aarch64N/APIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0
el9.x86_64PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0
el9.aarch64PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0
el10.x86_64PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0
el10.aarch64PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0
d12.x86_64PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0
d12.aarch64PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0
d13.x86_64PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0
d13.aarch64PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0
u22.x86_64PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0
u22.aarch64PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0
u24.x86_64PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0
u24.aarch64PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0
u26.x86_64PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0
u26.aarch64PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0PIGSTY 1.1.0
软件包版本平台仓库大小下载
pg_math_191.1.0el9.x86_64pigsty72.5 KiBpg_math_19-1.1.0-1PGSTY.el9.x86_64.rpm
pg_math_191.1.0el9.aarch64pigsty71.0 KiBpg_math_19-1.1.0-1PGSTY.el9.aarch64.rpm
pg_math_191.1.0el10.x86_64pigsty72.9 KiBpg_math_19-1.1.0-1PGSTY.el10.x86_64.rpm
pg_math_191.1.0el10.aarch64pigsty71.4 KiBpg_math_19-1.1.0-1PGSTY.el10.aarch64.rpm
postgresql-19-pg-math1.1.0d12.x86_64pigsty60.8 KiBpostgresql-19-pg-math_1.1.0-1PGSTY~bookworm_amd64.deb
postgresql-19-pg-math1.1.0d12.aarch64pigsty59.9 KiBpostgresql-19-pg-math_1.1.0-1PGSTY~bookworm_arm64.deb
postgresql-19-pg-math1.1.0d13.x86_64pigsty60.7 KiBpostgresql-19-pg-math_1.1.0-1PGSTY~trixie_amd64.deb
postgresql-19-pg-math1.1.0d13.aarch64pigsty60.2 KiBpostgresql-19-pg-math_1.1.0-1PGSTY~trixie_arm64.deb
postgresql-19-pg-math1.1.0u22.x86_64pigsty68.2 KiBpostgresql-19-pg-math_1.1.0-1PGSTY~jammy_amd64.deb
postgresql-19-pg-math1.1.0u22.aarch64pigsty67.1 KiBpostgresql-19-pg-math_1.1.0-1PGSTY~jammy_arm64.deb
postgresql-19-pg-math1.1.0u24.x86_64pigsty65.0 KiBpostgresql-19-pg-math_1.1.0-1PGSTY~noble_amd64.deb
postgresql-19-pg-math1.1.0u24.aarch64pigsty63.9 KiBpostgresql-19-pg-math_1.1.0-1PGSTY~noble_arm64.deb
postgresql-19-pg-math1.1.0u26.x86_64pigsty64.1 KiBpostgresql-19-pg-math_1.1.0-1PGSTY~resolute_amd64.deb
postgresql-19-pg-math1.1.0u26.aarch64pigsty63.6 KiBpostgresql-19-pg-math_1.1.0-1PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
pg_math_181.1.0el8.x86_64pigsty70.9 KiBpg_math_18-1.1.0-1PGSTY.el8.x86_64.rpm
pg_math_181.1.0el8.aarch64pigsty69.3 KiBpg_math_18-1.1.0-1PGSTY.el8.aarch64.rpm
pg_math_181.1.0el9.x86_64pigsty73.0 KiBpg_math_18-1.1.0-1PGSTY.el9.x86_64.rpm
pg_math_181.1.0el9.aarch64pigsty71.0 KiBpg_math_18-1.1.0-1PGSTY.el9.aarch64.rpm
pg_math_181.1.0el10.x86_64pigsty72.4 KiBpg_math_18-1.1.0-1PGSTY.el10.x86_64.rpm
pg_math_181.1.0el10.aarch64pigsty71.4 KiBpg_math_18-1.1.0-1PGSTY.el10.aarch64.rpm
postgresql-18-pg-math1.1.0d12.x86_64pigsty60.9 KiBpostgresql-18-pg-math_1.1.0-1PGSTY~bookworm_amd64.deb
postgresql-18-pg-math1.1.0d12.aarch64pigsty59.9 KiBpostgresql-18-pg-math_1.1.0-1PGSTY~bookworm_arm64.deb
postgresql-18-pg-math1.1.0d13.x86_64pigsty60.7 KiBpostgresql-18-pg-math_1.1.0-1PGSTY~trixie_amd64.deb
postgresql-18-pg-math1.1.0d13.aarch64pigsty60.3 KiBpostgresql-18-pg-math_1.1.0-1PGSTY~trixie_arm64.deb
postgresql-18-pg-math1.1.0u22.x86_64pigsty68.2 KiBpostgresql-18-pg-math_1.1.0-1PGSTY~jammy_amd64.deb
postgresql-18-pg-math1.1.0u22.aarch64pigsty67.1 KiBpostgresql-18-pg-math_1.1.0-1PGSTY~jammy_arm64.deb
postgresql-18-pg-math1.1.0u24.x86_64pigsty65.0 KiBpostgresql-18-pg-math_1.1.0-1PGSTY~noble_amd64.deb
postgresql-18-pg-math1.1.0u24.aarch64pigsty63.9 KiBpostgresql-18-pg-math_1.1.0-1PGSTY~noble_arm64.deb
postgresql-18-pg-math1.1.0u26.x86_64pigsty64.1 KiBpostgresql-18-pg-math_1.1.0-1PGSTY~resolute_amd64.deb
postgresql-18-pg-math1.1.0u26.aarch64pigsty63.5 KiBpostgresql-18-pg-math_1.1.0-1PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
pg_math_171.1.0el8.x86_64pigsty70.9 KiBpg_math_17-1.1.0-1PGSTY.el8.x86_64.rpm
pg_math_171.1.0el8.aarch64pigsty69.3 KiBpg_math_17-1.1.0-1PGSTY.el8.aarch64.rpm
pg_math_171.1.0el9.x86_64pigsty72.9 KiBpg_math_17-1.1.0-1PGSTY.el9.x86_64.rpm
pg_math_171.1.0el9.aarch64pigsty70.9 KiBpg_math_17-1.1.0-1PGSTY.el9.aarch64.rpm
pg_math_171.1.0el10.x86_64pigsty72.8 KiBpg_math_17-1.1.0-1PGSTY.el10.x86_64.rpm
pg_math_171.1.0el10.aarch64pigsty71.3 KiBpg_math_17-1.1.0-1PGSTY.el10.aarch64.rpm
postgresql-17-pg-math1.1.0d12.x86_64pigsty61.0 KiBpostgresql-17-pg-math_1.1.0-1PGSTY~bookworm_amd64.deb
postgresql-17-pg-math1.1.0d12.aarch64pigsty59.8 KiBpostgresql-17-pg-math_1.1.0-1PGSTY~bookworm_arm64.deb
postgresql-17-pg-math1.1.0d13.x86_64pigsty60.6 KiBpostgresql-17-pg-math_1.1.0-1PGSTY~trixie_amd64.deb
postgresql-17-pg-math1.1.0d13.aarch64pigsty60.1 KiBpostgresql-17-pg-math_1.1.0-1PGSTY~trixie_arm64.deb
postgresql-17-pg-math1.1.0u22.x86_64pigsty68.9 KiBpostgresql-17-pg-math_1.1.0-1PGSTY~jammy_amd64.deb
postgresql-17-pg-math1.1.0u22.aarch64pigsty67.9 KiBpostgresql-17-pg-math_1.1.0-1PGSTY~jammy_arm64.deb
postgresql-17-pg-math1.1.0u24.x86_64pigsty64.9 KiBpostgresql-17-pg-math_1.1.0-1PGSTY~noble_amd64.deb
postgresql-17-pg-math1.1.0u24.aarch64pigsty63.8 KiBpostgresql-17-pg-math_1.1.0-1PGSTY~noble_arm64.deb
postgresql-17-pg-math1.1.0u26.x86_64pigsty64.1 KiBpostgresql-17-pg-math_1.1.0-1PGSTY~resolute_amd64.deb
postgresql-17-pg-math1.1.0u26.aarch64pigsty63.4 KiBpostgresql-17-pg-math_1.1.0-1PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
pg_math_161.1.0el8.x86_64pigsty70.9 KiBpg_math_16-1.1.0-1PGSTY.el8.x86_64.rpm
pg_math_161.1.0el8.aarch64pigsty69.3 KiBpg_math_16-1.1.0-1PGSTY.el8.aarch64.rpm
pg_math_161.1.0el9.x86_64pigsty72.9 KiBpg_math_16-1.1.0-1PGSTY.el9.x86_64.rpm
pg_math_161.1.0el9.aarch64pigsty70.9 KiBpg_math_16-1.1.0-1PGSTY.el9.aarch64.rpm
pg_math_161.1.0el10.x86_64pigsty72.8 KiBpg_math_16-1.1.0-1PGSTY.el10.x86_64.rpm
pg_math_161.1.0el10.aarch64pigsty71.3 KiBpg_math_16-1.1.0-1PGSTY.el10.aarch64.rpm
postgresql-16-pg-math1.1.0d12.x86_64pigsty60.9 KiBpostgresql-16-pg-math_1.1.0-1PGSTY~bookworm_amd64.deb
postgresql-16-pg-math1.1.0d12.aarch64pigsty60.0 KiBpostgresql-16-pg-math_1.1.0-1PGSTY~bookworm_arm64.deb
postgresql-16-pg-math1.1.0d13.x86_64pigsty60.7 KiBpostgresql-16-pg-math_1.1.0-1PGSTY~trixie_amd64.deb
postgresql-16-pg-math1.1.0d13.aarch64pigsty60.1 KiBpostgresql-16-pg-math_1.1.0-1PGSTY~trixie_arm64.deb
postgresql-16-pg-math1.1.0u22.x86_64pigsty68.9 KiBpostgresql-16-pg-math_1.1.0-1PGSTY~jammy_amd64.deb
postgresql-16-pg-math1.1.0u22.aarch64pigsty67.9 KiBpostgresql-16-pg-math_1.1.0-1PGSTY~jammy_arm64.deb
postgresql-16-pg-math1.1.0u24.x86_64pigsty64.9 KiBpostgresql-16-pg-math_1.1.0-1PGSTY~noble_amd64.deb
postgresql-16-pg-math1.1.0u24.aarch64pigsty63.8 KiBpostgresql-16-pg-math_1.1.0-1PGSTY~noble_arm64.deb
postgresql-16-pg-math1.1.0u26.x86_64pigsty64.1 KiBpostgresql-16-pg-math_1.1.0-1PGSTY~resolute_amd64.deb
postgresql-16-pg-math1.1.0u26.aarch64pigsty63.4 KiBpostgresql-16-pg-math_1.1.0-1PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
pg_math_151.1.0el8.x86_64pigsty70.9 KiBpg_math_15-1.1.0-1PGSTY.el8.x86_64.rpm
pg_math_151.1.0el8.aarch64pigsty69.3 KiBpg_math_15-1.1.0-1PGSTY.el8.aarch64.rpm
pg_math_151.1.0el9.x86_64pigsty72.9 KiBpg_math_15-1.1.0-1PGSTY.el9.x86_64.rpm
pg_math_151.1.0el9.aarch64pigsty70.9 KiBpg_math_15-1.1.0-1PGSTY.el9.aarch64.rpm
pg_math_151.1.0el10.x86_64pigsty72.9 KiBpg_math_15-1.1.0-1PGSTY.el10.x86_64.rpm
pg_math_151.1.0el10.aarch64pigsty71.3 KiBpg_math_15-1.1.0-1PGSTY.el10.aarch64.rpm
postgresql-15-pg-math1.1.0d12.x86_64pigsty60.8 KiBpostgresql-15-pg-math_1.1.0-1PGSTY~bookworm_amd64.deb
postgresql-15-pg-math1.1.0d12.aarch64pigsty60.0 KiBpostgresql-15-pg-math_1.1.0-1PGSTY~bookworm_arm64.deb
postgresql-15-pg-math1.1.0d13.x86_64pigsty60.6 KiBpostgresql-15-pg-math_1.1.0-1PGSTY~trixie_amd64.deb
postgresql-15-pg-math1.1.0d13.aarch64pigsty60.3 KiBpostgresql-15-pg-math_1.1.0-1PGSTY~trixie_arm64.deb
postgresql-15-pg-math1.1.0u22.x86_64pigsty68.9 KiBpostgresql-15-pg-math_1.1.0-1PGSTY~jammy_amd64.deb
postgresql-15-pg-math1.1.0u22.aarch64pigsty67.9 KiBpostgresql-15-pg-math_1.1.0-1PGSTY~jammy_arm64.deb
postgresql-15-pg-math1.1.0u24.x86_64pigsty64.9 KiBpostgresql-15-pg-math_1.1.0-1PGSTY~noble_amd64.deb
postgresql-15-pg-math1.1.0u24.aarch64pigsty63.8 KiBpostgresql-15-pg-math_1.1.0-1PGSTY~noble_arm64.deb
postgresql-15-pg-math1.1.0u26.x86_64pigsty64.1 KiBpostgresql-15-pg-math_1.1.0-1PGSTY~resolute_amd64.deb
postgresql-15-pg-math1.1.0u26.aarch64pigsty63.4 KiBpostgresql-15-pg-math_1.1.0-1PGSTY~resolute_arm64.deb

源码

pig build pkg pg_math;		# build rpm/deb

安装

启用 PGDG 和 PIGSTY 仓库并更新缓存。

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

使用 pig 安装扩展。

pig install pg_math;		# install by package name

pig install pg_math -v 19;   # install for PG 19
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

在数据库中创建扩展。

CREATE EXTENSION pg_math;

用法

pg_math: 使用 GSL 的 PostgreSQL 统计分布函数

基于 GNU 科学计算库(GSL)提供 31 种统计分布的 CDF(累积分布函数)和 RDF(随机分布函数)。

CREATE EXTENSION pg_math;

支持的分布

高斯分布、单位高斯分布、高斯尾分布、二元高斯分布、F 分布、指数分布、拉普拉斯分布、指数幂分布、柯西分布、瑞利分布、瑞利尾分布、朗道分布、伽马分布、均匀分布、对数正态分布、卡方分布、t 分布、贝塔分布、逻辑斯蒂分布、帕累托分布、韦伯分布、第一类 Gumbel 分布、第二类 Gumbel 分布、泊松分布、伯努利分布、二项分布、负二项分布、帕斯卡分布、几何分布、超几何分布、对数分布。

函数命名约定

  • rdf_<distribution>(...) – 随机分布函数(概率密度值)
  • cdf_<distribution>_p(...) – 累积分布 P 值
  • cdf_<distribution>_q(...) – 累积分布 Q 值(1-P)
  • cdf_<distribution>_pinv(...) – 逆 CDF P
  • cdf_<distribution>_qinv(...) – 逆 CDF Q

示例

-- 高斯分布
SELECT rdf_gaussian(1.5, 2.0);            -- x=1.5, sigma=2.0 处的概率密度
SELECT cdf_gaussian_p(1.5, 2.0);          -- CDF P 值

-- 单位高斯分布(标准正态)
SELECT cdf_unit_gaussian_p(1.96);          -- ~0.975

-- 卡方分布
SELECT cdf_chisq_p(3.84, 1.0);            -- ~0.95

-- t 分布
SELECT cdf_tdist_pinv(0.975, 10.0);       -- df=10 时 95% 置信区间的临界值

-- 泊松分布
SELECT rdf_poisson(5, 3.0);               -- lambda=3 时 P(X=5)

-- 贝塔分布
SELECT rdf_beta(0.5, 2.0, 5.0);           -- x=0.5, a=2, b=5 处的概率密度

表格阅读器