aggs_for_arrays

计算数组聚合统计值的函数包

概览

扩展包名版本分类许可证语言
aggs_for_arrays1.3.3FUNCMITC
ID扩展名BinLibLoadCreateTrustReloc模式
4750aggs_for_arrays-
相关扩展aggs_for_vecs first_last_agg arraymath intarray topn quantile

版本

类型仓库版本PG 大版本包名依赖
EXTPIGSTY1.3.31817161514aggs_for_arrays-
RPMPIGSTY1.3.31817161514aggs_for_arrays_$v-
DEBPIGSTY1.3.31817161514postgresql-$v-aggs-for-arrays-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64
el8.aarch64
PIGSTY 1.3.3
PIGSTY 1.3.3
PIGSTY 1.3.3
PIGSTY 1.3.3
PIGSTY 1.3.3
el9.x86_64
el9.aarch64
PIGSTY 1.3.3
PIGSTY 1.3.3
PIGSTY 1.3.3
PIGSTY 1.3.3
PIGSTY 1.3.3
el10.x86_64
PIGSTY 1.3.3
PIGSTY 1.3.3
PIGSTY 1.3.3
PIGSTY 1.3.3
PIGSTY 1.3.3
el10.aarch64
PIGSTY 1.3.3
PIGSTY 1.3.3
PIGSTY 1.3.3
PIGSTY 1.3.3
PIGSTY 1.3.3
d12.x86_64
PIGSTY 1.3.3
PIGSTY 1.3.3
PIGSTY 1.3.3
PIGSTY 1.3.3
PIGSTY 1.3.3
d12.aarch64
PIGSTY 1.3.3
PIGSTY 1.3.3
PIGSTY 1.3.3
PIGSTY 1.3.3
PIGSTY 1.3.3
d13.x86_64
PIGSTY 1.3.3
PIGSTY 1.3.3
PIGSTY 1.3.3
PIGSTY 1.3.3
PIGSTY 1.3.3
d13.aarch64
PIGSTY 1.3.3
PIGSTY 1.3.3
PIGSTY 1.3.3
PIGSTY 1.3.3
PIGSTY 1.3.3
u22.x86_64
PIGSTY 1.3.3
PIGSTY 1.3.3
PIGSTY 1.3.3
PIGSTY 1.3.3
PIGSTY 1.3.3
u22.aarch64
PIGSTY 1.3.3
PIGSTY 1.3.3
PIGSTY 1.3.3
PIGSTY 1.3.3
PIGSTY 1.3.3
u24.x86_64
PIGSTY 1.3.3
PIGSTY 1.3.3
PIGSTY 1.3.3
PIGSTY 1.3.3
PIGSTY 1.3.3
u24.aarch64
PIGSTY 1.3.3
PIGSTY 1.3.3
PIGSTY 1.3.3
PIGSTY 1.3.3
PIGSTY 1.3.3

构建

您可以使用 pig build 命令构建 aggs_for_arrays 扩展的 RPM / DEB 包:

pig build pkg aggs_for_arrays         # 构建 RPM / DEB 包

安装

您可以直接安装 aggs_for_arrays 扩展包的预置二进制包,首先确保 PGDGPIGSTY 仓库已经添加并启用:

pig repo add pgsql -u          # 添加仓库并更新缓存

使用 pig 或者是 apt/yum/dnf 安装扩展:

pig install aggs_for_arrays;          # 当前活跃 PG 版本安装
pig ext install -y aggs_for_arrays -v 18  # PG 18
pig ext install -y aggs_for_arrays -v 17  # PG 17
pig ext install -y aggs_for_arrays -v 16  # PG 16
pig ext install -y aggs_for_arrays -v 15  # PG 15
pig ext install -y aggs_for_arrays -v 14  # PG 14
dnf install -y aggs_for_arrays_18       # PG 18
dnf install -y aggs_for_arrays_17       # PG 17
dnf install -y aggs_for_arrays_16       # PG 16
dnf install -y aggs_for_arrays_15       # PG 15
dnf install -y aggs_for_arrays_14       # PG 14
apt install -y postgresql-18-aggs-for-arrays   # PG 18
apt install -y postgresql-17-aggs-for-arrays   # PG 17
apt install -y postgresql-16-aggs-for-arrays   # PG 16
apt install -y postgresql-15-aggs-for-arrays   # PG 15
apt install -y postgresql-14-aggs-for-arrays   # PG 14

创建扩展

CREATE EXTENSION aggs_for_arrays;

用法

aggs_for_arrays: 单数组的类聚合函数(逐列模式)

提供对单个数组输入计算统计量的函数。支持 SMALLINTINTEGERBIGINTREALDOUBLE PRECISION 类型。

CREATE EXTENSION aggs_for_arrays;

函数

函数说明
array_to_hist(values T[], start T, width T, count INT)计算直方图分桶计数
array_to_hist_2d(x[], y[], ...)二维直方图
array_to_mean(values T[])数组元素的均值
array_to_median(values T[])中位数(输入无需排序)
sorted_array_to_median(values T[])中位数(输入已排序)
array_to_mode(values T[])数组元素的众数
sorted_array_to_mode(values T[])众数(输入已排序)
array_to_percentile(values T[], pct FLOAT)百分位数(0 到 1)
sorted_array_to_percentile(values T[], pct FLOAT)百分位数(输入已排序)
array_to_percentiles(values T[], pcts FLOAT[])多个百分位数
sorted_array_to_percentiles(values T[], pcts FLOAT[])多个百分位数(输入已排序)
array_to_max(values T[])最大元素
array_to_min(values T[])最小元素
array_to_min_max(values T[]){min, max} 元组
array_to_skewness(values T[])偏度
array_to_kurtosis(values T[])峰度

示例

-- 10 个分桶的直方图,起始值 0,桶宽 10
SELECT array_to_hist(ARRAY[5,15,25,35,45], 0, 10, 5);
-- {1,1,1,1,1}

-- 均值和中位数
SELECT array_to_mean(ARRAY[1,2,3,4,5]);   -- 3.0
SELECT array_to_median(ARRAY[1,2,3,4,5]); -- 3.0

-- 百分位数
SELECT array_to_percentile(ARRAY[1,2,3,4,5,6,7,8,9,10], 0.95);

-- 一次计算多个百分位数
SELECT array_to_percentiles(ARRAY[1,2,3,4,5], ARRAY[0.25, 0.5, 0.75]);

最后修改 2026-03-14: update extension metadata (953cbd0)