PostgreSQL 20 adds min() and max() aggregate functions for the uuid type. Since uuid already has a full set of comparison operators and a btree operator class, the patch simply adds uuid_larger() and uuid_smaller() support functions and registers the aggregates. UUIDs are compared lexicographically over their 128 bits. For UUIDv7, whose most significant bits encode a Unix timestamp, this means min() and max() correspond to the oldest and newest values respectively. The post demonstrates the feature with both UUIDv7 (timestamp-based) and random UUIDs.
13.8K Impressions