argm
argm : argmax, argmin, and anyold aggregate functions
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 4755 | argm | argm | 1.1.1 |
FUNC | PostgreSQL | C |
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
| --s-d-r | No | Yes | No | Yes | yes | no |
| Relationships | |
|---|---|
| See Also | tablefunc first_last_agg extra_window_functions pg_duckdb |
Packages
| Type | Repo | Version | PG Major Compatibility | Package Pattern | Dependencies |
|---|---|---|---|---|---|
| EXT | PIGSTY | 1.1.1 |
18 17 16 15 14 | argm |
- |
| RPM | PIGSTY | 1.1.1 |
18 17 16 15 14 | argm_$v |
- |
| DEB | PIGSTY | 1.1.1 |
18 17 16 15 14 | postgresql-$v-argm |
- |
| Linux / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
| el8.x86_64 | PIGSTY 1.1.1 | PIGSTY 1.1.1 | PIGSTY 1.1.1 | PIGSTY 1.1.1 | PIGSTY 1.1.1 |
| el8.aarch64 | PIGSTY 1.1.1 | PIGSTY 1.1.1 | PIGSTY 1.1.1 | PIGSTY 1.1.1 | PIGSTY 1.1.1 |
| el9.x86_64 | PIGSTY 1.1.1 | PIGSTY 1.1.1 | PIGSTY 1.1.1 | PIGSTY 1.1.1 | PIGSTY 1.1.1 |
| el9.aarch64 | PIGSTY 1.1.1 | PIGSTY 1.1.1 | PIGSTY 1.1.1 | PIGSTY 1.1.1 | PIGSTY 1.1.1 |
| el10.x86_64 | PIGSTY 1.1.1 | PIGSTY 1.1.1 | PIGSTY 1.1.1 | PIGSTY 1.1.1 | PIGSTY 1.1.1 |
| el10.aarch64 | PIGSTY 1.1.1 | PIGSTY 1.1.1 | PIGSTY 1.1.1 | PIGSTY 1.1.1 | PIGSTY 1.1.1 |
| d12.x86_64 | PIGSTY 1.1.1 | PIGSTY 1.1.1 | PIGSTY 1.1.1 | PIGSTY 1.1.1 | PIGSTY 1.1.1 |
| d12.aarch64 | PIGSTY 1.1.1 | PIGSTY 1.1.1 | PIGSTY 1.1.1 | PIGSTY 1.1.1 | PIGSTY 1.1.1 |
| d13.x86_64 | PIGSTY 1.1.1 | PIGSTY 1.1.1 | PIGSTY 1.1.1 | PIGSTY 1.1.1 | PIGSTY 1.1.1 |
| d13.aarch64 | PIGSTY 1.1.1 | PIGSTY 1.1.1 | PIGSTY 1.1.1 | PIGSTY 1.1.1 | PIGSTY 1.1.1 |
| u22.x86_64 | PIGSTY 1.1.1 | PIGSTY 1.1.1 | PIGSTY 1.1.1 | PIGSTY 1.1.1 | PIGSTY 1.1.1 |
| u22.aarch64 | PIGSTY 1.1.1 | PIGSTY 1.1.1 | PIGSTY 1.1.1 | PIGSTY 1.1.1 | PIGSTY 1.1.1 |
| u24.x86_64 | PIGSTY 1.1.1 | PIGSTY 1.1.1 | PIGSTY 1.1.1 | PIGSTY 1.1.1 | PIGSTY 1.1.1 |
| u24.aarch64 | PIGSTY 1.1.1 | PIGSTY 1.1.1 | PIGSTY 1.1.1 | PIGSTY 1.1.1 | PIGSTY 1.1.1 |
| u26.x86_64 | PIGSTY 1.1.1 | PIGSTY 1.1.1 | PIGSTY 1.1.1 | PIGSTY 1.1.1 | PIGSTY 1.1.1 |
| u26.aarch64 | PIGSTY 1.1.1 | PIGSTY 1.1.1 | PIGSTY 1.1.1 | PIGSTY 1.1.1 | PIGSTY 1.1.1 |
Source
github.com/bashtanov/argm
argm-1.1.1.tar.gz
Install
Make sure PGDG and PIGSTY repo available:
Install this extension with pig:
Create this extension with:
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
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:
Use anyold(value) when any member of a group is acceptable:
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.