first_last_agg
first_last_agg
first_last_agg : first() and last() aggregate functions
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 4710 | first_last_agg | first_last_agg | 0.1.4 | 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 | aggs_for_arrays aggs_for_vecs topn quantile lower_quantile count_distinct arraymath |
Packages
| Type | Repo | Version | PG Major Compatibility | Package Pattern | Dependencies |
|---|---|---|---|---|---|
| EXT | MIXED | 0.1.4 | 18 17 16 15 14 | first_last_agg | - |
| RPM | PIGSTY | 0.1.4 | 18 17 16 15 14 | first_last_agg_$v | - |
| DEB | PGDG | 0.1.4 | 18 17 16 15 14 | postgresql-$v-first-last-agg | - |
| Linux / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
el8.x86_64 | PIGSTY 0.1.4 | PIGSTY 0.1.4 | PIGSTY 0.1.4 | PIGSTY 0.1.4 | PIGSTY 0.1.4 |
el8.aarch64 | PIGSTY 0.1.4 | PIGSTY 0.1.4 | PIGSTY 0.1.4 | PIGSTY 0.1.4 | PIGSTY 0.1.4 |
el9.x86_64 | PIGSTY 0.1.4 | PIGSTY 0.1.4 | PIGSTY 0.1.4 | PIGSTY 0.1.4 | PIGSTY 0.1.4 |
el9.aarch64 | PIGSTY 0.1.4 | PIGSTY 0.1.4 | PIGSTY 0.1.4 | PIGSTY 0.1.4 | PIGSTY 0.1.4 |
el10.x86_64 | PIGSTY 0.1.4 | PIGSTY 0.1.4 | PIGSTY 0.1.4 | PIGSTY 0.1.4 | PIGSTY 0.1.4 |
el10.aarch64 | PIGSTY 0.1.4 | PIGSTY 0.1.4 | PIGSTY 0.1.4 | PIGSTY 0.1.4 | PIGSTY 0.1.4 |
d12.x86_64 | PGDG 0.1.4 | PGDG 0.1.4 | PGDG 0.1.4 | PGDG 0.1.4 | PGDG 0.1.4 |
d12.aarch64 | PGDG 0.1.4 | PGDG 0.1.4 | PGDG 0.1.4 | PGDG 0.1.4 | PGDG 0.1.4 |
d13.x86_64 | PGDG 0.1.4 | PGDG 0.1.4 | PGDG 0.1.4 | PGDG 0.1.4 | PGDG 0.1.4 |
d13.aarch64 | PGDG 0.1.4 | PGDG 0.1.4 | PGDG 0.1.4 | PGDG 0.1.4 | PGDG 0.1.4 |
u22.x86_64 | PGDG 0.1.4 | PGDG 0.1.4 | PGDG 0.1.4 | PGDG 0.1.4 | PGDG 0.1.4 |
u22.aarch64 | PGDG 0.1.4 | PGDG 0.1.4 | PGDG 0.1.4 | PGDG 0.1.4 | PGDG 0.1.4 |
u24.x86_64 | PGDG 0.1.4 | PGDG 0.1.4 | PGDG 0.1.4 | PGDG 0.1.4 | PGDG 0.1.4 |
u24.aarch64 | PGDG 0.1.4 | PGDG 0.1.4 | PGDG 0.1.4 | PGDG 0.1.4 | PGDG 0.1.4 |
Source
pig build pkg first_last_agg; # build rpmInstall
Make sure PGDG and PIGSTY repo available:
pig repo add pgsql -u # add both repo and update cacheInstall this extension with pig:
pig install first_last_agg; # install via package name, for the active PG version
pig install first_last_agg -v 18; # install for PG 18
pig install first_last_agg -v 17; # install for PG 17
pig install first_last_agg -v 16; # install for PG 16
pig install first_last_agg -v 15; # install for PG 15
pig install first_last_agg -v 14; # install for PG 14Create this extension with:
CREATE EXTENSION first_last_agg;Usage
first_last_agg: first and last aggregate functions for PostgreSQL
Provides first and last aggregate functions that return the first or last value in a group, operating on any element type.
CREATE EXTENSION first_last_agg;Functions
| Function | Description |
|---|---|
first(anyelement) | Return the first value in the group |
last(anyelement) | Return the last value in the group |
Examples
-- Get the first and last values (use ORDER BY for deterministic results)
SELECT id, first(val ORDER BY ts), last(val ORDER BY ts)
FROM events
GROUP BY id;
-- Without ORDER BY, the ordering within groups is undefined
SELECT department, first(salary ORDER BY hire_date)
FROM employees
GROUP BY department;Last updated on