Re: Add MIN/MAX aggregate support for uuid
Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
From: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
To: Tristan Partin <tristan@partin.io>
Cc: pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2026-06-24T05:58:47Z
Lists: pgsql-hackers
Hi, On Tue, Jun 23, 2026 at 11:05 AM Tristan Partin <tristan@partin.io> wrote: > > On Tue Jun 23, 2026 at 6:04 PM UTC, Tristan Partin wrote: > > I noticed that we support various comparison operators on uuid values. > > However, we were missing support for the MIN and MAX aggregate > > functions, which seems like a logical thing to also support if we > > support operators. > > > > The use case that I envision the most is finding the oldest and newest > > UUID v7 values in a set. UUID v7 is a timestamp-prefixed identifier. > > According to RFC 9562[0], the first 48 bits of a UUID v7 value are > > a Unix Epoch timestamp. Additionally, Postgres implements Method 3 of > > Section 6.2[1] for UUID v7 such that the next 12 bits bits store a > > 1/4096 (or 2^12) fraction of sub-millisecond precision. See the comment > > in generate_uuidv7() for more details. > > > > [0]: https://datatracker.ietf.org/doc/html/rfc9562#name-uuid-version-7 > > [1]: https://datatracker.ietf.org/doc/html/rfc9562#monotonicity_counters > > And of course no patch attached :(. The intent looks fine to me for UUIDv7. It would be interesting to understand why there's been no such support for versions < v7 so far in Postgres. Is there a limitation? A minor comment on the patch. 1/ + UUIDs are compared lexicographically on their 128-bit value. For version 7 UUIDs, How about using UUIDv7 instead of "version 7 UUIDs"? -- Bharath Rupireddy Amazon Web Services: https://aws.amazon.com
Commits
-
Add min() and max() aggregate support for uuid.
- 2e606d75c0bf master landed