Add min() and max() aggregate support for uuid.
Masahiko Sawada <msawada@postgresql.org>
Add min() and max() aggregate support for uuid. The uuid type already has a full set of comparison operators and a btree operator class, so it is totally ordered. min() and max() were the only common aggregates missing for it. Add the uuid_larger() and uuid_smaller() support functions and register the min(uuid) and max(uuid) aggregates that use them. uuid values are compared lexicographically over their 128 bits. For UUIDv7, whose most significant bits encode a Unix timestamp, this coincides with chronological order, so min() and max() return the oldest and newest values. Bump catalog version. Author: Tristan Partin <tristan@partin.io> Reviewed-by: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com> Reviewed-by: Zsolt Parragi <zsolt.parragi@percona.com> Reviewed-by: Masahiko Sawada <sawada.mshk@gmail.com> Discussion: https://postgr.es/m/DJGML0T9FCDV.3VA29JLODXEHZ@partin.io
Files
| Path | Change | +/− |
|---|---|---|
| doc/src/sgml/datatype.sgml | modified | +4 −0 |
| doc/src/sgml/func/func-aggregate.sgml | modified | +4 −2 |
| src/backend/utils/adt/uuid.c | modified | +18 −0 |
| src/include/catalog/catversion.h | modified | +1 −1 |
| src/include/catalog/pg_aggregate.dat | modified | +6 −0 |
| src/include/catalog/pg_proc.dat | modified | +12 −0 |
| src/test/regress/expected/opr_sanity.out | modified | +2 −0 |
| src/test/regress/expected/uuid.out | modified | +7 −0 |
| src/test/regress/sql/uuid.sql | modified | +3 −0 |
Documentation touched
Discussion
- Add MIN/MAX aggregate support for uuid 12 messages · 2026-06-23 → 2026-07-01