Skip to content

first_last_agg

first() and last() aggregate functions

first_last_agg · first() and last() aggregate functions

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
4720first_last_aggfirst_last_agg0.1.4FUNCPostgreSQLC
AttributeHas BinaryHas LibraryNeed LoadHas DDLRelocatableTrusted
--s-d-rNoYesNoYesyesno

Packages

TypeRepoVersionPG Major CompatibilityPackage PatternDependencies
EXTMIXED0.1.419 18 17 16 15first_last_agg-
RPMPIGSTY0.1.419 18 17 16 15first_last_agg_$v-
DEBPGDG0.1.419 18 17 16 15postgresql-$v-first-last-agg-
Linux / PGPG19PG18PG17PG16PG15
el8.x86_64N/APIGSTY 0.1.4PIGSTY 0.1.4PIGSTY 0.1.4PIGSTY 0.1.4
el8.aarch64N/APIGSTY 0.1.4PIGSTY 0.1.4PIGSTY 0.1.4PIGSTY 0.1.4
el9.x86_64PIGSTY 0.1.4PIGSTY 0.1.4PIGSTY 0.1.4PIGSTY 0.1.4PIGSTY 0.1.4
el9.aarch64PIGSTY 0.1.4PIGSTY 0.1.4PIGSTY 0.1.4PIGSTY 0.1.4PIGSTY 0.1.4
el10.x86_64PIGSTY 0.1.4PIGSTY 0.1.4PIGSTY 0.1.4PIGSTY 0.1.4PIGSTY 0.1.4
el10.aarch64PIGSTY 0.1.4PIGSTY 0.1.4PIGSTY 0.1.4PIGSTY 0.1.4PIGSTY 0.1.4
d12.x86_64PIGSTY 0.1.4PGDG 0.1.4PGDG 0.1.4PGDG 0.1.4PGDG 0.1.4
d12.aarch64PIGSTY 0.1.4PGDG 0.1.4PGDG 0.1.4PGDG 0.1.4PGDG 0.1.4
d13.x86_64PIGSTY 0.1.4PGDG 0.1.4PGDG 0.1.4PGDG 0.1.4PGDG 0.1.4
d13.aarch64PIGSTY 0.1.4PGDG 0.1.4PGDG 0.1.4PGDG 0.1.4PGDG 0.1.4
u22.x86_64PIGSTY 0.1.4PGDG 0.1.4PGDG 0.1.4PGDG 0.1.4PGDG 0.1.4
u22.aarch64PIGSTY 0.1.4PGDG 0.1.4PGDG 0.1.4PGDG 0.1.4PGDG 0.1.4
u24.x86_64PIGSTY 0.1.4PGDG 0.1.4PGDG 0.1.4PGDG 0.1.4PGDG 0.1.4
u24.aarch64PIGSTY 0.1.4PGDG 0.1.4PGDG 0.1.4PGDG 0.1.4PGDG 0.1.4
u26.x86_64PIGSTY 0.1.4PGDG 0.1.4PGDG 0.1.4PGDG 0.1.4PGDG 0.1.4
u26.aarch64PIGSTY 0.1.4PGDG 0.1.4PGDG 0.1.4PGDG 0.1.4PGDG 0.1.4
PackageVersionOSORGSIZEFile URL
first_last_agg_190.1.4el9.x86_64pigsty15.3 KiBfirst_last_agg_19-0.1.4-1PGSTY.el9.x86_64.rpm
first_last_agg_190.1.4el9.aarch64pigsty15.4 KiBfirst_last_agg_19-0.1.4-1PGSTY.el9.aarch64.rpm
first_last_agg_190.1.4el10.x86_64pigsty15.2 KiBfirst_last_agg_19-0.1.4-1PGSTY.el10.x86_64.rpm
first_last_agg_190.1.4el10.aarch64pigsty15.5 KiBfirst_last_agg_19-0.1.4-1PGSTY.el10.aarch64.rpm
postgresql-19-first-last-agg0.1.4d12.x86_64pigsty8.7 KiBpostgresql-19-first-last-agg_0.1.4-2PGSTY~bookworm_amd64.deb
postgresql-19-first-last-agg0.1.4d12.aarch64pigsty8.6 KiBpostgresql-19-first-last-agg_0.1.4-2PGSTY~bookworm_arm64.deb
postgresql-19-first-last-agg0.1.4d13.x86_64pigsty8.7 KiBpostgresql-19-first-last-agg_0.1.4-2PGSTY~trixie_amd64.deb
postgresql-19-first-last-agg0.1.4d13.aarch64pigsty8.7 KiBpostgresql-19-first-last-agg_0.1.4-2PGSTY~trixie_arm64.deb
postgresql-19-first-last-agg0.1.4u22.x86_64pigsty8.8 KiBpostgresql-19-first-last-agg_0.1.4-2PGSTY~jammy_amd64.deb
postgresql-19-first-last-agg0.1.4u22.aarch64pigsty9.0 KiBpostgresql-19-first-last-agg_0.1.4-2PGSTY~jammy_arm64.deb
postgresql-19-first-last-agg0.1.4u24.x86_64pigsty9.0 KiBpostgresql-19-first-last-agg_0.1.4-2PGSTY~noble_amd64.deb
postgresql-19-first-last-agg0.1.4u24.aarch64pigsty8.9 KiBpostgresql-19-first-last-agg_0.1.4-2PGSTY~noble_arm64.deb
postgresql-19-first-last-agg0.1.4u26.x86_64pigsty8.9 KiBpostgresql-19-first-last-agg_0.1.4-2PGSTY~resolute_amd64.deb
postgresql-19-first-last-agg0.1.4u26.aarch64pigsty9.2 KiBpostgresql-19-first-last-agg_0.1.4-2PGSTY~resolute_arm64.deb
PackageVersionOSORGSIZEFile URL
first_last_agg_180.1.4el8.x86_64pigsty15.4 KiBfirst_last_agg_18-0.1.4-1PGSTY.el8.x86_64.rpm
first_last_agg_180.1.4el8.aarch64pigsty15.8 KiBfirst_last_agg_18-0.1.4-1PGSTY.el8.aarch64.rpm
first_last_agg_180.1.4el9.x86_64pigsty15.3 KiBfirst_last_agg_18-0.1.4-1PGSTY.el9.x86_64.rpm
first_last_agg_180.1.4el9.aarch64pigsty15.4 KiBfirst_last_agg_18-0.1.4-1PGSTY.el9.aarch64.rpm
first_last_agg_180.1.4el10.x86_64pigsty15.3 KiBfirst_last_agg_18-0.1.4-1PGSTY.el10.x86_64.rpm
first_last_agg_180.1.4el10.aarch64pigsty15.5 KiBfirst_last_agg_18-0.1.4-1PGSTY.el10.aarch64.rpm
postgresql-18-first-last-agg0.1.4d12.x86_64pgdg8.6 KiBpostgresql-18-first-last-agg_0.1.4-4-gd63ea3b-9.pgdg12+1_amd64.deb
postgresql-18-first-last-agg0.1.4d12.aarch64pgdg8.5 KiBpostgresql-18-first-last-agg_0.1.4-4-gd63ea3b-9.pgdg12+1_arm64.deb
postgresql-18-first-last-agg0.1.4d13.x86_64pgdg8.6 KiBpostgresql-18-first-last-agg_0.1.4-4-gd63ea3b-9.pgdg13+1_amd64.deb
postgresql-18-first-last-agg0.1.4d13.aarch64pgdg8.5 KiBpostgresql-18-first-last-agg_0.1.4-4-gd63ea3b-9.pgdg13+1_arm64.deb
postgresql-18-first-last-agg0.1.4u22.x86_64pgdg8.4 KiBpostgresql-18-first-last-agg_0.1.4-4-gd63ea3b-9.pgdg22.04+1_amd64.deb
postgresql-18-first-last-agg0.1.4u22.aarch64pgdg8.5 KiBpostgresql-18-first-last-agg_0.1.4-4-gd63ea3b-9.pgdg22.04+1_arm64.deb
postgresql-18-first-last-agg0.1.4u24.x86_64pgdg8.6 KiBpostgresql-18-first-last-agg_0.1.4-4-gd63ea3b-9.pgdg24.04+1_amd64.deb
postgresql-18-first-last-agg0.1.4u24.aarch64pgdg8.5 KiBpostgresql-18-first-last-agg_0.1.4-4-gd63ea3b-9.pgdg24.04+1_arm64.deb
postgresql-18-first-last-agg0.1.4u26.x86_64pgdg8.5 KiBpostgresql-18-first-last-agg_0.1.4-4-gd63ea3b-9.pgdg26.04+1_amd64.deb
postgresql-18-first-last-agg0.1.4u26.aarch64pgdg8.9 KiBpostgresql-18-first-last-agg_0.1.4-4-gd63ea3b-9.pgdg26.04+1_arm64.deb
PackageVersionOSORGSIZEFile URL
first_last_agg_170.1.4el8.x86_64pigsty15.3 KiBfirst_last_agg_17-0.1.4-1PGSTY.el8.x86_64.rpm
first_last_agg_170.1.4el8.aarch64pigsty15.7 KiBfirst_last_agg_17-0.1.4-1PGSTY.el8.aarch64.rpm
first_last_agg_170.1.4el9.x86_64pigsty15.2 KiBfirst_last_agg_17-0.1.4-1PGSTY.el9.x86_64.rpm
first_last_agg_170.1.4el9.aarch64pigsty15.4 KiBfirst_last_agg_17-0.1.4-1PGSTY.el9.aarch64.rpm
first_last_agg_170.1.4el10.x86_64pigsty15.2 KiBfirst_last_agg_17-0.1.4-1PGSTY.el10.x86_64.rpm
first_last_agg_170.1.4el10.aarch64pigsty15.5 KiBfirst_last_agg_17-0.1.4-1PGSTY.el10.aarch64.rpm
postgresql-17-first-last-agg0.1.4d12.x86_64pgdg8.6 KiBpostgresql-17-first-last-agg_0.1.4-4-gd63ea3b-9.pgdg12+1_amd64.deb
postgresql-17-first-last-agg0.1.4d12.aarch64pgdg8.5 KiBpostgresql-17-first-last-agg_0.1.4-4-gd63ea3b-9.pgdg12+1_arm64.deb
postgresql-17-first-last-agg0.1.4d13.x86_64pgdg8.6 KiBpostgresql-17-first-last-agg_0.1.4-4-gd63ea3b-9.pgdg13+1_amd64.deb
postgresql-17-first-last-agg0.1.4d13.aarch64pgdg8.5 KiBpostgresql-17-first-last-agg_0.1.4-4-gd63ea3b-9.pgdg13+1_arm64.deb
postgresql-17-first-last-agg0.1.4u22.x86_64pgdg8.4 KiBpostgresql-17-first-last-agg_0.1.4-4-gd63ea3b-9.pgdg22.04+1_amd64.deb
postgresql-17-first-last-agg0.1.4u22.aarch64pgdg8.6 KiBpostgresql-17-first-last-agg_0.1.4-4-gd63ea3b-9.pgdg22.04+1_arm64.deb
postgresql-17-first-last-agg0.1.4u24.x86_64pgdg8.6 KiBpostgresql-17-first-last-agg_0.1.4-4-gd63ea3b-9.pgdg24.04+1_amd64.deb
postgresql-17-first-last-agg0.1.4u24.aarch64pgdg8.5 KiBpostgresql-17-first-last-agg_0.1.4-4-gd63ea3b-9.pgdg24.04+1_arm64.deb
postgresql-17-first-last-agg0.1.4u26.x86_64pgdg8.6 KiBpostgresql-17-first-last-agg_0.1.4-4-gd63ea3b-9.pgdg26.04+1_amd64.deb
postgresql-17-first-last-agg0.1.4u26.aarch64pgdg8.9 KiBpostgresql-17-first-last-agg_0.1.4-4-gd63ea3b-9.pgdg26.04+1_arm64.deb
PackageVersionOSORGSIZEFile URL
first_last_agg_160.1.4el8.x86_64pigsty15.3 KiBfirst_last_agg_16-0.1.4-1PGSTY.el8.x86_64.rpm
first_last_agg_160.1.4el8.aarch64pigsty15.7 KiBfirst_last_agg_16-0.1.4-1PGSTY.el8.aarch64.rpm
first_last_agg_160.1.4el9.x86_64pigsty15.2 KiBfirst_last_agg_16-0.1.4-1PGSTY.el9.x86_64.rpm
first_last_agg_160.1.4el9.aarch64pigsty15.4 KiBfirst_last_agg_16-0.1.4-1PGSTY.el9.aarch64.rpm
first_last_agg_160.1.4el10.x86_64pigsty15.2 KiBfirst_last_agg_16-0.1.4-1PGSTY.el10.x86_64.rpm
first_last_agg_160.1.4el10.aarch64pigsty15.5 KiBfirst_last_agg_16-0.1.4-1PGSTY.el10.aarch64.rpm
postgresql-16-first-last-agg0.1.4d12.x86_64pgdg8.6 KiBpostgresql-16-first-last-agg_0.1.4-4-gd63ea3b-9.pgdg12+1_amd64.deb
postgresql-16-first-last-agg0.1.4d12.aarch64pgdg8.5 KiBpostgresql-16-first-last-agg_0.1.4-4-gd63ea3b-9.pgdg12+1_arm64.deb
postgresql-16-first-last-agg0.1.4d13.x86_64pgdg8.6 KiBpostgresql-16-first-last-agg_0.1.4-4-gd63ea3b-9.pgdg13+1_amd64.deb
postgresql-16-first-last-agg0.1.4d13.aarch64pgdg8.5 KiBpostgresql-16-first-last-agg_0.1.4-4-gd63ea3b-9.pgdg13+1_arm64.deb
postgresql-16-first-last-agg0.1.4u22.x86_64pgdg8.4 KiBpostgresql-16-first-last-agg_0.1.4-4-gd63ea3b-9.pgdg22.04+1_amd64.deb
postgresql-16-first-last-agg0.1.4u22.aarch64pgdg8.6 KiBpostgresql-16-first-last-agg_0.1.4-4-gd63ea3b-9.pgdg22.04+1_arm64.deb
postgresql-16-first-last-agg0.1.4u24.x86_64pgdg8.6 KiBpostgresql-16-first-last-agg_0.1.4-4-gd63ea3b-9.pgdg24.04+1_amd64.deb
postgresql-16-first-last-agg0.1.4u24.aarch64pgdg8.5 KiBpostgresql-16-first-last-agg_0.1.4-4-gd63ea3b-9.pgdg24.04+1_arm64.deb
postgresql-16-first-last-agg0.1.4u26.x86_64pgdg8.6 KiBpostgresql-16-first-last-agg_0.1.4-4-gd63ea3b-9.pgdg26.04+1_amd64.deb
postgresql-16-first-last-agg0.1.4u26.aarch64pgdg8.9 KiBpostgresql-16-first-last-agg_0.1.4-4-gd63ea3b-9.pgdg26.04+1_arm64.deb
PackageVersionOSORGSIZEFile URL
first_last_agg_150.1.4el8.x86_64pigsty15.3 KiBfirst_last_agg_15-0.1.4-1PGSTY.el8.x86_64.rpm
first_last_agg_150.1.4el8.aarch64pigsty15.7 KiBfirst_last_agg_15-0.1.4-1PGSTY.el8.aarch64.rpm
first_last_agg_150.1.4el9.x86_64pigsty15.2 KiBfirst_last_agg_15-0.1.4-1PGSTY.el9.x86_64.rpm
first_last_agg_150.1.4el9.aarch64pigsty15.4 KiBfirst_last_agg_15-0.1.4-1PGSTY.el9.aarch64.rpm
first_last_agg_150.1.4el10.x86_64pigsty15.2 KiBfirst_last_agg_15-0.1.4-1PGSTY.el10.x86_64.rpm
first_last_agg_150.1.4el10.aarch64pigsty15.5 KiBfirst_last_agg_15-0.1.4-1PGSTY.el10.aarch64.rpm
postgresql-15-first-last-agg0.1.4d12.x86_64pgdg8.6 KiBpostgresql-15-first-last-agg_0.1.4-4-gd63ea3b-9.pgdg12+1_amd64.deb
postgresql-15-first-last-agg0.1.4d12.aarch64pgdg8.5 KiBpostgresql-15-first-last-agg_0.1.4-4-gd63ea3b-9.pgdg12+1_arm64.deb
postgresql-15-first-last-agg0.1.4d13.x86_64pgdg8.6 KiBpostgresql-15-first-last-agg_0.1.4-4-gd63ea3b-9.pgdg13+1_amd64.deb
postgresql-15-first-last-agg0.1.4d13.aarch64pgdg8.5 KiBpostgresql-15-first-last-agg_0.1.4-4-gd63ea3b-9.pgdg13+1_arm64.deb
postgresql-15-first-last-agg0.1.4u22.x86_64pgdg8.4 KiBpostgresql-15-first-last-agg_0.1.4-4-gd63ea3b-9.pgdg22.04+1_amd64.deb
postgresql-15-first-last-agg0.1.4u22.aarch64pgdg8.6 KiBpostgresql-15-first-last-agg_0.1.4-4-gd63ea3b-9.pgdg22.04+1_arm64.deb
postgresql-15-first-last-agg0.1.4u24.x86_64pgdg8.6 KiBpostgresql-15-first-last-agg_0.1.4-4-gd63ea3b-9.pgdg24.04+1_amd64.deb
postgresql-15-first-last-agg0.1.4u24.aarch64pgdg8.5 KiBpostgresql-15-first-last-agg_0.1.4-4-gd63ea3b-9.pgdg24.04+1_arm64.deb
postgresql-15-first-last-agg0.1.4u26.x86_64pgdg8.5 KiBpostgresql-15-first-last-agg_0.1.4-4-gd63ea3b-9.pgdg26.04+1_amd64.deb
postgresql-15-first-last-agg0.1.4u26.aarch64pgdg8.9 KiBpostgresql-15-first-last-agg_0.1.4-4-gd63ea3b-9.pgdg26.04+1_arm64.deb

Source

pig build pkg first_last_agg;		# 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 first_last_agg;		# install by package name

pig install first_last_agg -v 19;   # install for PG 19
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

Create 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

FunctionDescription
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;

Table reader