argm
Overview
| Package | Version | Category | License | Language |
|---|---|---|---|---|
argm | 1.1.1 | FUNC | PostgreSQL | C |
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 4755 | argm | No | Yes | No | Yes | No | Yes | - |
| Related | tablefunc first_last_agg extra_window_functions pg_duckdb |
|---|
fix pg16+ varlena header with patch
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | PIGSTY | 1.1.1 | 1817161514 | argm | - |
| RPM | PIGSTY | 1.1.1 | 1817161514 | argm_$v | - |
| DEB | PIGSTY | 1.1.1 | 1817161514 | postgresql-$v-argm | - |
Build
You can build the RPM / DEB packages for argm using pig build:
pig build pkg argm # build RPM / DEB packages
Install
You can install argm 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 argm; # Install for current active PG version
pig ext install -y argm -v 18 # PG 18
pig ext install -y argm -v 17 # PG 17
pig ext install -y argm -v 16 # PG 16
pig ext install -y argm -v 15 # PG 15
pig ext install -y argm -v 14 # PG 14
dnf install -y argm_18 # PG 18
dnf install -y argm_17 # PG 17
dnf install -y argm_16 # PG 16
dnf install -y argm_15 # PG 15
dnf install -y argm_14 # PG 14
apt install -y postgresql-18-argm # PG 18
apt install -y postgresql-17-argm # PG 17
apt install -y postgresql-16-argm # PG 16
apt install -y postgresql-15-argm # PG 15
apt install -y postgresql-14-argm # PG 14
Create Extension:
CREATE EXTENSION argm;
Usage
Sources:
argm provides the polymorphic aggregates argmax, argmin, and anyold. They return a value from a selected row while grouping, avoiding a join or window-function pass when the row can be chosen by one or more sortable keys.
Core Workflow
CREATE EXTENSION argm;
SELECT customer_id,
argmax(order_id, total, ordered_at) AS largest_order
FROM orders
GROUP BY customer_id;
argmax(value, key...) returns the value belonging to the lexicographically greatest key tuple. argmin selects the least tuple. Additional keys break ties without building a composite value:
SELECT device_id,
argmax(reading, measured_at, sequence_no) AS latest_reading
FROM measurements
GROUP BY device_id;
Use anyold(value) when any member of a group is acceptable:
SELECT account_id, anyold(display_name)
FROM account_aliases
GROUP BY account_id;
Important Objects
argmax(value, key [, key ...])selects the value associated with the greatest key tuple.argmin(value, key [, key ...])selects the value associated with the least key tuple.anyold(value)returns an arbitrary non-null value from the aggregate state.
The aggregates accept any value type; key types must have ordering support. The SQL definitions are parallel-safe and include combine and serialization functions for partial aggregation.
Semantics and Caveats
Key tuples use one ordering direction and one collation for the whole tuple, with null keys sorted last. If complete key tuples tie, the chosen value is unspecified; add a stable final key when deterministic results matter. As with other PostgreSQL aggregates, empty input produces NULL.
argm 1.1.x requires PostgreSQL 9.6 or newer. The extension is relocatable. Upgrading from 1.0.3 to 1.1.x requires dropping and recreating the extension because the aggregate state changed; the 1.1.0-to-1.1.1 upgrade does not change the public SQL surface.
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.