aggs_for_arrays

aggs_for_arrays

aggs_for_arrays : Various functions for computing statistics on arrays of numbers

Overview

ID Extension Package Version Category License Language
4750
aggs_for_arrays
aggs_for_arrays
1.3.3
FUNC
MIT
C
Attribute Has Binary Has Library Need Load Has DDL Relocatable Trusted
--s-d-r
No
Yes
No
Yes
yes
no
Relationships
See Also
aggs_for_vecs
first_last_agg
arraymath
intarray
topn
quantile

Packages

Type Repo Version PG Major Compatibility Package Pattern Dependencies
EXT
PIGSTY
1.3.3
18
17
16
15
14
aggs_for_arrays -
RPM
PIGSTY
1.3.3
18
17
16
15
14
aggs_for_arrays_$v -
DEB
PIGSTY
1.3.3
18
17
16
15
14
postgresql-$v-aggs-for-arrays -
Linux / PG PG18 PG17 PG16 PG15 PG14
el8.x86_64
PIGSTY 1.3.3
PIGSTY 1.3.3
PIGSTY 1.3.3
PIGSTY 1.3.3
PIGSTY 1.3.3
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
PIGSTY 1.3.3
PIGSTY 1.3.3
PIGSTY 1.3.3
PIGSTY 1.3.3
PIGSTY 1.3.3
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
Package Version OS ORG SIZE File URL
aggs_for_arrays_18 1.3.3 el8.x86_64 pigsty 27.6 KiB aggs_for_arrays_18-1.3.3-1PIGSTY.el8.x86_64.rpm
aggs_for_arrays_18 1.3.3 el8.aarch64 pigsty 30.8 KiB aggs_for_arrays_18-1.3.3-1PIGSTY.el8.aarch64.rpm
aggs_for_arrays_18 1.3.3 el9.x86_64 pigsty 26.9 KiB aggs_for_arrays_18-1.3.3-1PIGSTY.el9.x86_64.rpm
aggs_for_arrays_18 1.3.3 el9.aarch64 pigsty 31.3 KiB aggs_for_arrays_18-1.3.3-1PIGSTY.el9.aarch64.rpm
aggs_for_arrays_18 1.3.3 el10.x86_64 pigsty 27.8 KiB aggs_for_arrays_18-1.3.3-1PIGSTY.el10.x86_64.rpm
aggs_for_arrays_18 1.3.3 el10.aarch64 pigsty 33.7 KiB aggs_for_arrays_18-1.3.3-1PIGSTY.el10.aarch64.rpm
postgresql-18-aggs-for-arrays 1.3.3 d12.x86_64 pigsty 42.3 KiB postgresql-18-aggs-for-arrays_1.3.3-1PIGSTY~bookworm_amd64.deb
postgresql-18-aggs-for-arrays 1.3.3 d12.aarch64 pigsty 46.8 KiB postgresql-18-aggs-for-arrays_1.3.3-1PIGSTY~bookworm_arm64.deb
postgresql-18-aggs-for-arrays 1.3.3 d13.x86_64 pigsty 42.9 KiB postgresql-18-aggs-for-arrays_1.3.3-1PIGSTY~trixie_amd64.deb
postgresql-18-aggs-for-arrays 1.3.3 d13.aarch64 pigsty 47.7 KiB postgresql-18-aggs-for-arrays_1.3.3-1PIGSTY~trixie_arm64.deb
postgresql-18-aggs-for-arrays 1.3.3 u22.x86_64 pigsty 44.3 KiB postgresql-18-aggs-for-arrays_1.3.3-1PIGSTY~jammy_amd64.deb
postgresql-18-aggs-for-arrays 1.3.3 u22.aarch64 pigsty 48.4 KiB postgresql-18-aggs-for-arrays_1.3.3-1PIGSTY~jammy_arm64.deb
postgresql-18-aggs-for-arrays 1.3.3 u24.x86_64 pigsty 43.6 KiB postgresql-18-aggs-for-arrays_1.3.3-1PIGSTY~noble_amd64.deb
postgresql-18-aggs-for-arrays 1.3.3 u24.aarch64 pigsty 49.7 KiB postgresql-18-aggs-for-arrays_1.3.3-1PIGSTY~noble_arm64.deb
Package Version OS ORG SIZE File URL
aggs_for_arrays_17 1.3.3 el8.x86_64 pigsty 27.6 KiB aggs_for_arrays_17-1.3.3-1PIGSTY.el8.x86_64.rpm
aggs_for_arrays_17 1.3.3 el8.aarch64 pigsty 30.8 KiB aggs_for_arrays_17-1.3.3-1PIGSTY.el8.aarch64.rpm
aggs_for_arrays_17 1.3.3 el9.x86_64 pigsty 26.9 KiB aggs_for_arrays_17-1.3.3-1PIGSTY.el9.x86_64.rpm
aggs_for_arrays_17 1.3.3 el9.aarch64 pigsty 31.2 KiB aggs_for_arrays_17-1.3.3-1PIGSTY.el9.aarch64.rpm
aggs_for_arrays_17 1.3.3 el10.x86_64 pigsty 27.8 KiB aggs_for_arrays_17-1.3.3-1PIGSTY.el10.x86_64.rpm
aggs_for_arrays_17 1.3.3 el10.aarch64 pigsty 33.7 KiB aggs_for_arrays_17-1.3.3-1PIGSTY.el10.aarch64.rpm
postgresql-17-aggs-for-arrays 1.3.3 d12.x86_64 pigsty 42.4 KiB postgresql-17-aggs-for-arrays_1.3.3-1PIGSTY~bookworm_amd64.deb
postgresql-17-aggs-for-arrays 1.3.3 d12.aarch64 pigsty 46.9 KiB postgresql-17-aggs-for-arrays_1.3.3-1PIGSTY~bookworm_arm64.deb
postgresql-17-aggs-for-arrays 1.3.3 d13.x86_64 pigsty 42.9 KiB postgresql-17-aggs-for-arrays_1.3.3-1PIGSTY~trixie_amd64.deb
postgresql-17-aggs-for-arrays 1.3.3 d13.aarch64 pigsty 47.8 KiB postgresql-17-aggs-for-arrays_1.3.3-1PIGSTY~trixie_arm64.deb
postgresql-17-aggs-for-arrays 1.3.3 u22.x86_64 pigsty 45.6 KiB postgresql-17-aggs-for-arrays_1.3.3-1PIGSTY~jammy_amd64.deb
postgresql-17-aggs-for-arrays 1.3.3 u22.aarch64 pigsty 49.8 KiB postgresql-17-aggs-for-arrays_1.3.3-1PIGSTY~jammy_arm64.deb
postgresql-17-aggs-for-arrays 1.3.3 u24.x86_64 pigsty 43.6 KiB postgresql-17-aggs-for-arrays_1.3.3-1PIGSTY~noble_amd64.deb
postgresql-17-aggs-for-arrays 1.3.3 u24.aarch64 pigsty 49.7 KiB postgresql-17-aggs-for-arrays_1.3.3-1PIGSTY~noble_arm64.deb
Package Version OS ORG SIZE File URL
aggs_for_arrays_16 1.3.3 el8.x86_64 pigsty 27.6 KiB aggs_for_arrays_16-1.3.3-1PIGSTY.el8.x86_64.rpm
aggs_for_arrays_16 1.3.3 el8.aarch64 pigsty 30.9 KiB aggs_for_arrays_16-1.3.3-1PIGSTY.el8.aarch64.rpm
aggs_for_arrays_16 1.3.3 el9.x86_64 pigsty 26.8 KiB aggs_for_arrays_16-1.3.3-1PIGSTY.el9.x86_64.rpm
aggs_for_arrays_16 1.3.3 el9.aarch64 pigsty 31.3 KiB aggs_for_arrays_16-1.3.3-1PIGSTY.el9.aarch64.rpm
aggs_for_arrays_16 1.3.3 el10.x86_64 pigsty 27.8 KiB aggs_for_arrays_16-1.3.3-1PIGSTY.el10.x86_64.rpm
aggs_for_arrays_16 1.3.3 el10.aarch64 pigsty 33.7 KiB aggs_for_arrays_16-1.3.3-1PIGSTY.el10.aarch64.rpm
postgresql-16-aggs-for-arrays 1.3.3 d12.x86_64 pigsty 42.4 KiB postgresql-16-aggs-for-arrays_1.3.3-1PIGSTY~bookworm_amd64.deb
postgresql-16-aggs-for-arrays 1.3.3 d12.aarch64 pigsty 46.9 KiB postgresql-16-aggs-for-arrays_1.3.3-1PIGSTY~bookworm_arm64.deb
postgresql-16-aggs-for-arrays 1.3.3 d13.x86_64 pigsty 42.9 KiB postgresql-16-aggs-for-arrays_1.3.3-1PIGSTY~trixie_amd64.deb
postgresql-16-aggs-for-arrays 1.3.3 d13.aarch64 pigsty 47.9 KiB postgresql-16-aggs-for-arrays_1.3.3-1PIGSTY~trixie_arm64.deb
postgresql-16-aggs-for-arrays 1.3.3 u22.x86_64 pigsty 45.6 KiB postgresql-16-aggs-for-arrays_1.3.3-1PIGSTY~jammy_amd64.deb
postgresql-16-aggs-for-arrays 1.3.3 u22.aarch64 pigsty 49.8 KiB postgresql-16-aggs-for-arrays_1.3.3-1PIGSTY~jammy_arm64.deb
postgresql-16-aggs-for-arrays 1.3.3 u24.x86_64 pigsty 43.6 KiB postgresql-16-aggs-for-arrays_1.3.3-1PIGSTY~noble_amd64.deb
postgresql-16-aggs-for-arrays 1.3.3 u24.aarch64 pigsty 49.7 KiB postgresql-16-aggs-for-arrays_1.3.3-1PIGSTY~noble_arm64.deb
Package Version OS ORG SIZE File URL
aggs_for_arrays_15 1.3.3 el8.x86_64 pigsty 27.7 KiB aggs_for_arrays_15-1.3.3-1PIGSTY.el8.x86_64.rpm
aggs_for_arrays_15 1.3.3 el8.aarch64 pigsty 31.0 KiB aggs_for_arrays_15-1.3.3-1PIGSTY.el8.aarch64.rpm
aggs_for_arrays_15 1.3.3 el9.x86_64 pigsty 27.0 KiB aggs_for_arrays_15-1.3.3-1PIGSTY.el9.x86_64.rpm
aggs_for_arrays_15 1.3.3 el9.aarch64 pigsty 31.4 KiB aggs_for_arrays_15-1.3.3-1PIGSTY.el9.aarch64.rpm
aggs_for_arrays_15 1.3.3 el10.x86_64 pigsty 27.9 KiB aggs_for_arrays_15-1.3.3-1PIGSTY.el10.x86_64.rpm
aggs_for_arrays_15 1.3.3 el10.aarch64 pigsty 33.9 KiB aggs_for_arrays_15-1.3.3-1PIGSTY.el10.aarch64.rpm
postgresql-15-aggs-for-arrays 1.3.3 d12.x86_64 pigsty 42.6 KiB postgresql-15-aggs-for-arrays_1.3.3-1PIGSTY~bookworm_amd64.deb
postgresql-15-aggs-for-arrays 1.3.3 d12.aarch64 pigsty 47.1 KiB postgresql-15-aggs-for-arrays_1.3.3-1PIGSTY~bookworm_arm64.deb
postgresql-15-aggs-for-arrays 1.3.3 d13.x86_64 pigsty 43.1 KiB postgresql-15-aggs-for-arrays_1.3.3-1PIGSTY~trixie_amd64.deb
postgresql-15-aggs-for-arrays 1.3.3 d13.aarch64 pigsty 48.0 KiB postgresql-15-aggs-for-arrays_1.3.3-1PIGSTY~trixie_arm64.deb
postgresql-15-aggs-for-arrays 1.3.3 u22.x86_64 pigsty 45.7 KiB postgresql-15-aggs-for-arrays_1.3.3-1PIGSTY~jammy_amd64.deb
postgresql-15-aggs-for-arrays 1.3.3 u22.aarch64 pigsty 50.1 KiB postgresql-15-aggs-for-arrays_1.3.3-1PIGSTY~jammy_arm64.deb
postgresql-15-aggs-for-arrays 1.3.3 u24.x86_64 pigsty 43.8 KiB postgresql-15-aggs-for-arrays_1.3.3-1PIGSTY~noble_amd64.deb
postgresql-15-aggs-for-arrays 1.3.3 u24.aarch64 pigsty 50.0 KiB postgresql-15-aggs-for-arrays_1.3.3-1PIGSTY~noble_arm64.deb
Package Version OS ORG SIZE File URL
aggs_for_arrays_14 1.3.3 el8.x86_64 pigsty 27.7 KiB aggs_for_arrays_14-1.3.3-1PIGSTY.el8.x86_64.rpm
aggs_for_arrays_14 1.3.3 el8.aarch64 pigsty 31.0 KiB aggs_for_arrays_14-1.3.3-1PIGSTY.el8.aarch64.rpm
aggs_for_arrays_14 1.3.3 el9.x86_64 pigsty 27.0 KiB aggs_for_arrays_14-1.3.3-1PIGSTY.el9.x86_64.rpm
aggs_for_arrays_14 1.3.3 el9.aarch64 pigsty 31.4 KiB aggs_for_arrays_14-1.3.3-1PIGSTY.el9.aarch64.rpm
aggs_for_arrays_14 1.3.3 el10.x86_64 pigsty 27.9 KiB aggs_for_arrays_14-1.3.3-1PIGSTY.el10.x86_64.rpm
aggs_for_arrays_14 1.3.3 el10.aarch64 pigsty 33.9 KiB aggs_for_arrays_14-1.3.3-1PIGSTY.el10.aarch64.rpm
postgresql-14-aggs-for-arrays 1.3.3 d12.x86_64 pigsty 42.6 KiB postgresql-14-aggs-for-arrays_1.3.3-1PIGSTY~bookworm_amd64.deb
postgresql-14-aggs-for-arrays 1.3.3 d12.aarch64 pigsty 47.2 KiB postgresql-14-aggs-for-arrays_1.3.3-1PIGSTY~bookworm_arm64.deb
postgresql-14-aggs-for-arrays 1.3.3 d13.x86_64 pigsty 43.1 KiB postgresql-14-aggs-for-arrays_1.3.3-1PIGSTY~trixie_amd64.deb
postgresql-14-aggs-for-arrays 1.3.3 d13.aarch64 pigsty 48.0 KiB postgresql-14-aggs-for-arrays_1.3.3-1PIGSTY~trixie_arm64.deb
postgresql-14-aggs-for-arrays 1.3.3 u22.x86_64 pigsty 45.6 KiB postgresql-14-aggs-for-arrays_1.3.3-1PIGSTY~jammy_amd64.deb
postgresql-14-aggs-for-arrays 1.3.3 u22.aarch64 pigsty 50.0 KiB postgresql-14-aggs-for-arrays_1.3.3-1PIGSTY~jammy_arm64.deb
postgresql-14-aggs-for-arrays 1.3.3 u24.x86_64 pigsty 43.8 KiB postgresql-14-aggs-for-arrays_1.3.3-1PIGSTY~noble_amd64.deb
postgresql-14-aggs-for-arrays 1.3.3 u24.aarch64 pigsty 50.1 KiB postgresql-14-aggs-for-arrays_1.3.3-1PIGSTY~noble_arm64.deb

Source

pig build pkg aggs_for_arrays;		# build rpm/deb

Install

Make sure PGDG and PIGSTY repo available:

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

Install this extension with pig:

pig install aggs_for_arrays;		# install via package name, for the active PG version

pig install aggs_for_arrays -v 18;   # install for PG 18
pig install aggs_for_arrays -v 17;   # install for PG 17
pig install aggs_for_arrays -v 16;   # install for PG 16
pig install aggs_for_arrays -v 15;   # install for PG 15
pig install aggs_for_arrays -v 14;   # install for PG 14

Create this extension with:

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

Function Description
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 updated on