aggs_for_vecs
Aggregate functions for array inputs
Repository
pjungwir/aggs_for_vecs
https://github.com/pjungwir/aggs_for_vecs
Source
aggs_for_vecs-1.4.1.tar.gz
aggs_for_vecs-1.4.1.tar.gz
Overview
| Package | Version | Category | License | Language |
|---|---|---|---|---|
aggs_for_vecs | 1.4.1 | FUNC | MIT | C |
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 4740 | aggs_for_vecs | No | Yes | No | Yes | No | Yes | - |
| Related | aggs_for_arrays first_last_agg arraymath floatvec vector topn |
|---|
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | PIGSTY | 1.4.1 | 1817161514 | aggs_for_vecs | - |
| RPM | PIGSTY | 1.4.1 | 1817161514 | aggs_for_vecs_$v | - |
| DEB | PIGSTY | 1.4.1 | 1817161514 | postgresql-$v-aggs-for-vecs | - |
Build
You can build the RPM / DEB packages for aggs_for_vecs using pig build:
pig build pkg aggs_for_vecs # build RPM / DEB packages
Install
You can install aggs_for_vecs 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_vecs; # Install for current active PG version
pig ext install -y aggs_for_vecs -v 18 # PG 18
pig ext install -y aggs_for_vecs -v 17 # PG 17
pig ext install -y aggs_for_vecs -v 16 # PG 16
pig ext install -y aggs_for_vecs -v 15 # PG 15
pig ext install -y aggs_for_vecs -v 14 # PG 14
dnf install -y aggs_for_vecs_18 # PG 18
dnf install -y aggs_for_vecs_17 # PG 17
dnf install -y aggs_for_vecs_16 # PG 16
dnf install -y aggs_for_vecs_15 # PG 15
dnf install -y aggs_for_vecs_14 # PG 14
apt install -y postgresql-18-aggs-for-vecs # PG 18
apt install -y postgresql-17-aggs-for-vecs # PG 17
apt install -y postgresql-16-aggs-for-vecs # PG 16
apt install -y postgresql-15-aggs-for-vecs # PG 15
apt install -y postgresql-14-aggs-for-vecs # PG 14
Create Extension:
CREATE EXTENSION aggs_for_vecs;
Usage
aggs_for_vecs: aggregate functions for arrays (vector/row-based)
Provides aggregate functions that operate on arrays as vectors, computing position-wise statistics across multiple rows. Supports SMALLINT, INTEGER, BIGINT, REAL, and DOUBLE PRECISION.
CREATE EXTENSION aggs_for_vecs;
Aggregate Functions
| Function | Description |
|---|---|
vec_to_count(anyarray) | Count of non-nulls in each position |
vec_to_sum(anyarray) | Sum in each position |
vec_to_min(anyarray) | Minimum in each position |
vec_to_max(anyarray) | Maximum in each position |
vec_to_mean(anyarray) | Average in each position (returns FLOAT[]) |
vec_to_weighted_mean(values, weights) | Weighted average in each position |
vec_to_var_samp(anyarray) | Sample variance in each position |
vec_to_first(anyarray) | First non-null in each position (use with ORDER BY) |
vec_to_last(anyarray) | Last non-null in each position (use with ORDER BY) |
hist_2d(x, y, ...) | 2-D histogram |
hist_md(vals, indexes, ...) | N-dimensional histogram |
Non-Aggregate Functions
| Function | Description |
|---|---|
vec_add(l, r) | Element-wise addition |
vec_sub(l, r) | Element-wise subtraction |
vec_mul(l, r) | Element-wise multiplication |
vec_div(l, r) | Element-wise division |
vec_elements(array, indexes) | Select elements at given indexes |
pad_vec(array, length) | Extend array to given length with NULLs |
vec_coalesce(array, default) | Replace NULLs with default |
vec_trim_scale(numeric[]) | Trim trailing zeros from NUMERIC elements |
vec_without_outliers(vals, mins, maxs) | Replace outliers with NULL |
Examples
-- Position-wise minimum across rows
SELECT vec_to_min(vals) FROM (VALUES
(ARRAY[1,2,3,4]),
(ARRAY[5,0,-5,0]),
(ARRAY[3,6,0,9])
) AS t(vals);
-- {1,0,-5,0}
-- Position-wise average
SELECT vec_to_mean(vals) FROM my_table;
Feedback
Was this page helpful?
Thanks for the feedback! Please let us know how we can improve.
Sorry to hear that. Please let us know how we can improve.