aggs_for_arrays

Various functions for computing statistics on arrays of numbers

Overview

PackageVersionCategoryLicenseLanguage
aggs_for_arrays1.3.3FUNCMITC
IDExtensionBinLibLoadCreateTrustRelocSchema
4750aggs_for_arraysNoYesNoYesNoYes-
Relatedaggs_for_vecs first_last_agg arraymath intarray topn quantile

Version

TypeRepoVersionPG VerPackageDeps
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

Build

You can build the RPM / DEB packages for aggs_for_arrays using pig build:

pig build pkg aggs_for_arrays         # build RPM / DEB packages

Install

You can install aggs_for_arrays 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 aggs_for_arrays;          # Install for current active PG version
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:

CREATE EXTENSION aggs_for_arrays;

Usage

aggs_for_arrays: aggregate-like functions for single arrays (column-based)

Provides functions that compute statistics on a single array input. Supports SMALLINT, INTEGER, BIGINT, REAL, and DOUBLE PRECISION.

CREATE EXTENSION aggs_for_arrays;

Functions

FunctionDescription
array_to_hist(values T[], start T, width T, count INT)Compute histogram bucket counts
array_to_hist_2d(x[], y[], ...)2-D histogram
array_to_mean(values T[])Mean of array elements
array_to_median(values T[])Median (unsorted input OK)
sorted_array_to_median(values T[])Median (pre-sorted input)
array_to_mode(values T[])Mode of array elements
sorted_array_to_mode(values T[])Mode (pre-sorted input)
array_to_percentile(values T[], pct FLOAT)Percentile (0 to 1)
sorted_array_to_percentile(values T[], pct FLOAT)Percentile (pre-sorted input)
array_to_percentiles(values T[], pcts FLOAT[])Multiple percentiles
sorted_array_to_percentiles(values T[], pcts FLOAT[])Multiple percentiles (pre-sorted)
array_to_max(values T[])Maximum element
array_to_min(values T[])Minimum element
array_to_min_max(values T[]){min, max} tuple
array_to_skewness(values T[])Skewness
array_to_kurtosis(values T[])Kurtosis

Examples

-- Histogram with 10 buckets starting at 0, width 10
SELECT array_to_hist(ARRAY[5,15,25,35,45], 0, 10, 5);
-- {1,1,1,1,1}

-- Mean and median
SELECT array_to_mean(ARRAY[1,2,3,4,5]);   -- 3.0
SELECT array_to_median(ARRAY[1,2,3,4,5]); -- 3.0

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

-- Multiple percentiles at once
SELECT array_to_percentiles(ARRAY[1,2,3,4,5], ARRAY[0.25, 0.5, 0.75]);

Last Modified 2026-03-12: add pg extension catalog (95749bf)