跳转到主要内容

quantile

Quantile聚合函数

quantile · Quantile聚合函数

概览

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

软件包

类型仓库版本兼容的 PostgreSQL 大版本包名模式依赖
EXTPIGSTY1.1.819 18 17 16 15quantile-
RPMPIGSTY1.1.819 18 17 16 15quantile_$v-
DEBPIGSTY1.1.819 18 17 16 15postgresql-$v-quantile-
Linux / PGPG19PG18PG17PG16PG15
el8.x86_64N/APIGSTY 1.1.8PIGSTY 1.1.8PIGSTY 1.1.8PIGSTY 1.1.8
el8.aarch64N/APIGSTY 1.1.8PIGSTY 1.1.8PIGSTY 1.1.8PIGSTY 1.1.8
el9.x86_64PIGSTY 1.1.8PIGSTY 1.1.8PIGSTY 1.1.8PIGSTY 1.1.8PIGSTY 1.1.8
el9.aarch64PIGSTY 1.1.8PIGSTY 1.1.8PIGSTY 1.1.8PIGSTY 1.1.8PIGSTY 1.1.8
el10.x86_64PIGSTY 1.1.8PIGSTY 1.1.8PIGSTY 1.1.8PIGSTY 1.1.8PIGSTY 1.1.8
el10.aarch64PIGSTY 1.1.8PIGSTY 1.1.8PIGSTY 1.1.8PIGSTY 1.1.8PIGSTY 1.1.8
d12.x86_64PIGSTY 1.1.8PIGSTY 1.1.8PIGSTY 1.1.8PIGSTY 1.1.8PIGSTY 1.1.8
d12.aarch64PIGSTY 1.1.8PIGSTY 1.1.8PIGSTY 1.1.8PIGSTY 1.1.8PIGSTY 1.1.8
d13.x86_64PIGSTY 1.1.8PIGSTY 1.1.8PIGSTY 1.1.8PIGSTY 1.1.8PIGSTY 1.1.8
d13.aarch64PIGSTY 1.1.8PIGSTY 1.1.8PIGSTY 1.1.8PIGSTY 1.1.8PIGSTY 1.1.8
u22.x86_64PIGSTY 1.1.8PIGSTY 1.1.8PIGSTY 1.1.8PIGSTY 1.1.8PIGSTY 1.1.8
u22.aarch64PIGSTY 1.1.8PIGSTY 1.1.8PIGSTY 1.1.8PIGSTY 1.1.8PIGSTY 1.1.8
u24.x86_64PIGSTY 1.1.8PIGSTY 1.1.8PIGSTY 1.1.8PIGSTY 1.1.8PIGSTY 1.1.8
u24.aarch64PIGSTY 1.1.8PIGSTY 1.1.8PIGSTY 1.1.8PIGSTY 1.1.8PIGSTY 1.1.8
u26.x86_64PIGSTY 1.1.8PIGSTY 1.1.8PIGSTY 1.1.8PIGSTY 1.1.8PIGSTY 1.1.8
u26.aarch64PIGSTY 1.1.8PIGSTY 1.1.8PIGSTY 1.1.8PIGSTY 1.1.8PIGSTY 1.1.8
软件包版本平台仓库大小下载
quantile_191.1.8el9.x86_64pigsty30.0 KiBquantile_19-1.1.8-1PGSTY.el9.x86_64.rpm
quantile_191.1.8el9.aarch64pigsty29.3 KiBquantile_19-1.1.8-1PGSTY.el9.aarch64.rpm
quantile_191.1.8el10.x86_64pigsty30.2 KiBquantile_19-1.1.8-1PGSTY.el10.x86_64.rpm
quantile_191.1.8el10.aarch64pigsty29.8 KiBquantile_19-1.1.8-1PGSTY.el10.aarch64.rpm
postgresql-19-quantile1.1.8d12.x86_64pigsty21.6 KiBpostgresql-19-quantile_1.1.8-1PGSTY~bookworm_amd64.deb
postgresql-19-quantile1.1.8d12.aarch64pigsty21.3 KiBpostgresql-19-quantile_1.1.8-1PGSTY~bookworm_arm64.deb
postgresql-19-quantile1.1.8d13.x86_64pigsty21.6 KiBpostgresql-19-quantile_1.1.8-1PGSTY~trixie_amd64.deb
postgresql-19-quantile1.1.8d13.aarch64pigsty21.4 KiBpostgresql-19-quantile_1.1.8-1PGSTY~trixie_arm64.deb
postgresql-19-quantile1.1.8u22.x86_64pigsty22.8 KiBpostgresql-19-quantile_1.1.8-1PGSTY~jammy_amd64.deb
postgresql-19-quantile1.1.8u22.aarch64pigsty21.9 KiBpostgresql-19-quantile_1.1.8-1PGSTY~jammy_arm64.deb
postgresql-19-quantile1.1.8u24.x86_64pigsty22.6 KiBpostgresql-19-quantile_1.1.8-1PGSTY~noble_amd64.deb
postgresql-19-quantile1.1.8u24.aarch64pigsty22.3 KiBpostgresql-19-quantile_1.1.8-1PGSTY~noble_arm64.deb
postgresql-19-quantile1.1.8u26.x86_64pigsty22.6 KiBpostgresql-19-quantile_1.1.8-1PGSTY~resolute_amd64.deb
postgresql-19-quantile1.1.8u26.aarch64pigsty22.3 KiBpostgresql-19-quantile_1.1.8-1PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
quantile_181.1.8el8.x86_64pigsty29.6 KiBquantile_18-1.1.8-1PGSTY.el8.x86_64.rpm
quantile_181.1.8el8.aarch64pigsty28.9 KiBquantile_18-1.1.8-1PGSTY.el8.aarch64.rpm
quantile_181.1.8el9.x86_64pigsty30.0 KiBquantile_18-1.1.8-1PGSTY.el9.x86_64.rpm
quantile_181.1.8el9.aarch64pigsty29.3 KiBquantile_18-1.1.8-1PGSTY.el9.aarch64.rpm
quantile_181.1.8el10.x86_64pigsty30.2 KiBquantile_18-1.1.8-1PGSTY.el10.x86_64.rpm
quantile_181.1.8el10.aarch64pigsty29.8 KiBquantile_18-1.1.8-1PGSTY.el10.aarch64.rpm
postgresql-18-quantile1.1.8d12.x86_64pigsty21.6 KiBpostgresql-18-quantile_1.1.8-1PGSTY~bookworm_amd64.deb
postgresql-18-quantile1.1.8d12.aarch64pigsty21.3 KiBpostgresql-18-quantile_1.1.8-1PGSTY~bookworm_arm64.deb
postgresql-18-quantile1.1.8d13.x86_64pigsty21.6 KiBpostgresql-18-quantile_1.1.8-1PGSTY~trixie_amd64.deb
postgresql-18-quantile1.1.8d13.aarch64pigsty21.4 KiBpostgresql-18-quantile_1.1.8-1PGSTY~trixie_arm64.deb
postgresql-18-quantile1.1.8u22.x86_64pigsty22.8 KiBpostgresql-18-quantile_1.1.8-1PGSTY~jammy_amd64.deb
postgresql-18-quantile1.1.8u22.aarch64pigsty21.9 KiBpostgresql-18-quantile_1.1.8-1PGSTY~jammy_arm64.deb
postgresql-18-quantile1.1.8u24.x86_64pigsty22.6 KiBpostgresql-18-quantile_1.1.8-1PGSTY~noble_amd64.deb
postgresql-18-quantile1.1.8u24.aarch64pigsty22.3 KiBpostgresql-18-quantile_1.1.8-1PGSTY~noble_arm64.deb
postgresql-18-quantile1.1.8u26.x86_64pigsty22.6 KiBpostgresql-18-quantile_1.1.8-1PGSTY~resolute_amd64.deb
postgresql-18-quantile1.1.8u26.aarch64pigsty22.3 KiBpostgresql-18-quantile_1.1.8-1PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
quantile_171.1.8el8.x86_64pigsty29.5 KiBquantile_17-1.1.8-1PGSTY.el8.x86_64.rpm
quantile_171.1.8el8.aarch64pigsty28.9 KiBquantile_17-1.1.8-1PGSTY.el8.aarch64.rpm
quantile_171.1.8el9.x86_64pigsty30.0 KiBquantile_17-1.1.8-1PGSTY.el9.x86_64.rpm
quantile_171.1.8el9.aarch64pigsty29.3 KiBquantile_17-1.1.8-1PGSTY.el9.aarch64.rpm
quantile_171.1.8el10.x86_64pigsty30.1 KiBquantile_17-1.1.8-1PGSTY.el10.x86_64.rpm
quantile_171.1.8el10.aarch64pigsty29.7 KiBquantile_17-1.1.8-1PGSTY.el10.aarch64.rpm
postgresql-17-quantile1.1.8d12.x86_64pigsty21.3 KiBpostgresql-17-quantile_1.1.8-1PGSTY~bookworm_amd64.deb
postgresql-17-quantile1.1.8d12.aarch64pigsty21.0 KiBpostgresql-17-quantile_1.1.8-1PGSTY~bookworm_arm64.deb
postgresql-17-quantile1.1.8d13.x86_64pigsty21.3 KiBpostgresql-17-quantile_1.1.8-1PGSTY~trixie_amd64.deb
postgresql-17-quantile1.1.8d13.aarch64pigsty21.1 KiBpostgresql-17-quantile_1.1.8-1PGSTY~trixie_arm64.deb
postgresql-17-quantile1.1.8u22.x86_64pigsty24.0 KiBpostgresql-17-quantile_1.1.8-1PGSTY~jammy_amd64.deb
postgresql-17-quantile1.1.8u22.aarch64pigsty23.1 KiBpostgresql-17-quantile_1.1.8-1PGSTY~jammy_arm64.deb
postgresql-17-quantile1.1.8u24.x86_64pigsty22.4 KiBpostgresql-17-quantile_1.1.8-1PGSTY~noble_amd64.deb
postgresql-17-quantile1.1.8u24.aarch64pigsty22.1 KiBpostgresql-17-quantile_1.1.8-1PGSTY~noble_arm64.deb
postgresql-17-quantile1.1.8u26.x86_64pigsty22.5 KiBpostgresql-17-quantile_1.1.8-1PGSTY~resolute_amd64.deb
postgresql-17-quantile1.1.8u26.aarch64pigsty22.1 KiBpostgresql-17-quantile_1.1.8-1PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
quantile_161.1.8el8.x86_64pigsty29.5 KiBquantile_16-1.1.8-1PGSTY.el8.x86_64.rpm
quantile_161.1.8el8.aarch64pigsty28.8 KiBquantile_16-1.1.8-1PGSTY.el8.aarch64.rpm
quantile_161.1.8el9.x86_64pigsty29.9 KiBquantile_16-1.1.8-1PGSTY.el9.x86_64.rpm
quantile_161.1.8el9.aarch64pigsty29.2 KiBquantile_16-1.1.8-1PGSTY.el9.aarch64.rpm
quantile_161.1.8el10.x86_64pigsty30.0 KiBquantile_16-1.1.8-1PGSTY.el10.x86_64.rpm
quantile_161.1.8el10.aarch64pigsty29.6 KiBquantile_16-1.1.8-1PGSTY.el10.aarch64.rpm
postgresql-16-quantile1.1.8d12.x86_64pigsty21.3 KiBpostgresql-16-quantile_1.1.8-1PGSTY~bookworm_amd64.deb
postgresql-16-quantile1.1.8d12.aarch64pigsty21.0 KiBpostgresql-16-quantile_1.1.8-1PGSTY~bookworm_arm64.deb
postgresql-16-quantile1.1.8d13.x86_64pigsty21.3 KiBpostgresql-16-quantile_1.1.8-1PGSTY~trixie_amd64.deb
postgresql-16-quantile1.1.8d13.aarch64pigsty21.1 KiBpostgresql-16-quantile_1.1.8-1PGSTY~trixie_arm64.deb
postgresql-16-quantile1.1.8u22.x86_64pigsty23.9 KiBpostgresql-16-quantile_1.1.8-1PGSTY~jammy_amd64.deb
postgresql-16-quantile1.1.8u22.aarch64pigsty23.1 KiBpostgresql-16-quantile_1.1.8-1PGSTY~jammy_arm64.deb
postgresql-16-quantile1.1.8u24.x86_64pigsty22.3 KiBpostgresql-16-quantile_1.1.8-1PGSTY~noble_amd64.deb
postgresql-16-quantile1.1.8u24.aarch64pigsty22.0 KiBpostgresql-16-quantile_1.1.8-1PGSTY~noble_arm64.deb
postgresql-16-quantile1.1.8u26.x86_64pigsty22.5 KiBpostgresql-16-quantile_1.1.8-1PGSTY~resolute_amd64.deb
postgresql-16-quantile1.1.8u26.aarch64pigsty22.1 KiBpostgresql-16-quantile_1.1.8-1PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
quantile_151.1.8el8.x86_64pigsty29.5 KiBquantile_15-1.1.8-1PGSTY.el8.x86_64.rpm
quantile_151.1.8el8.aarch64pigsty28.8 KiBquantile_15-1.1.8-1PGSTY.el8.aarch64.rpm
quantile_151.1.8el9.x86_64pigsty29.9 KiBquantile_15-1.1.8-1PGSTY.el9.x86_64.rpm
quantile_151.1.8el9.aarch64pigsty29.2 KiBquantile_15-1.1.8-1PGSTY.el9.aarch64.rpm
quantile_151.1.8el10.x86_64pigsty30.0 KiBquantile_15-1.1.8-1PGSTY.el10.x86_64.rpm
quantile_151.1.8el10.aarch64pigsty29.6 KiBquantile_15-1.1.8-1PGSTY.el10.aarch64.rpm
postgresql-15-quantile1.1.8d12.x86_64pigsty21.3 KiBpostgresql-15-quantile_1.1.8-1PGSTY~bookworm_amd64.deb
postgresql-15-quantile1.1.8d12.aarch64pigsty21.0 KiBpostgresql-15-quantile_1.1.8-1PGSTY~bookworm_arm64.deb
postgresql-15-quantile1.1.8d13.x86_64pigsty21.3 KiBpostgresql-15-quantile_1.1.8-1PGSTY~trixie_amd64.deb
postgresql-15-quantile1.1.8d13.aarch64pigsty21.1 KiBpostgresql-15-quantile_1.1.8-1PGSTY~trixie_arm64.deb
postgresql-15-quantile1.1.8u22.x86_64pigsty23.7 KiBpostgresql-15-quantile_1.1.8-1PGSTY~jammy_amd64.deb
postgresql-15-quantile1.1.8u22.aarch64pigsty22.8 KiBpostgresql-15-quantile_1.1.8-1PGSTY~jammy_arm64.deb
postgresql-15-quantile1.1.8u24.x86_64pigsty22.3 KiBpostgresql-15-quantile_1.1.8-1PGSTY~noble_amd64.deb
postgresql-15-quantile1.1.8u24.aarch64pigsty22.0 KiBpostgresql-15-quantile_1.1.8-1PGSTY~noble_arm64.deb
postgresql-15-quantile1.1.8u26.x86_64pigsty22.7 KiBpostgresql-15-quantile_1.1.8-1PGSTY~resolute_amd64.deb
postgresql-15-quantile1.1.8u26.aarch64pigsty22.1 KiBpostgresql-15-quantile_1.1.8-1PGSTY~resolute_arm64.deb

源码

pig build pkg quantile;		# build rpm/deb

安装

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

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

使用 pig 安装扩展。

pig install quantile;		# install by package name

pig install quantile -v 19;   # install for PG 19
pig install quantile -v 18;   # install for PG 18
pig install quantile -v 17;   # install for PG 17
pig install quantile -v 16;   # install for PG 16
pig install quantile -v 15;   # install for PG 15

在数据库中创建扩展。

CREATE EXTENSION quantile;

用法

quantile: PostgreSQL 的分位数聚合函数

提供计算分位数的聚合函数,支持 int、bigint、double precision 和 numeric 类型的重载。

CREATE EXTENSION quantile;

函数

函数描述
quantile(value, quantile float)计算单个分位数(0 到 1)
quantile(value, quantiles float[])一次计算多个分位数,返回数组

示例

-- 计算中位数(0.5 分位数)
SELECT quantile(i, 0.5) FROM generate_series(1, 1000) s(i);
-- 500

-- 计算第 95 百分位数
SELECT quantile(i, 0.95) FROM generate_series(1, 1000) s(i);

-- 一次计算所有四分位数(比分别调用更高效)
SELECT quantile(i, ARRAY[0.25, 0.5, 0.75])
FROM generate_series(1, 1000) s(i);
-- {250, 500, 750}

注意:自 PostgreSQL 9.4 起,内置的 percentile_cont 和 percentile_disc 函数已经可用。建议优先使用内置函数,仅在该扩展对您的工作负载有明显性能优势时才使用它。

表格阅读器