<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/waiting-for-postgresql-20-add-min-and-max-aggregate-support-for-uuid-select-from-depesz--zwdjdsv2s" -->

---
title: Waiting for PostgreSQL 20 – Add min() and max()...
description: 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,...
canonical: https://daily.dev/posts/waiting-for-postgresql-20-add-min-and-max-aggregate-support-for-uuid-select-from-depesz--zwdjdsv2s
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Waiting for PostgreSQL 20 – Add min() and max() aggregate support for uuid. – select * from depesz; | daily.dev
og:description: 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,...
og:url: https://daily.dev/posts/waiting-for-postgresql-20-add-min-and-max-aggregate-support-for-uuid-select-from-depesz--zwdjdsv2s
og:image: https://api.daily.dev/og/posts/ZwdJdSv2S.png
og:image:alt: Waiting for PostgreSQL 20 – Add min() and max() aggregate support for uuid. – select * from depesz;
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Waiting for PostgreSQL 20 – Add min() and max() aggregate support for uuid. – select * from depesz;

**[depesz](https://daily.dev/sources/depesz)** · 3 min read · 4 upvotes · 0 comments

## Summary

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.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.depesz.com/2026/07/09/waiting-for-postgresql-20-add-min-and-max-aggregate-support-for-uuid>

## Questions this post answers

### Does PostgreSQL support min() and max() aggregate functions on uuid columns?

Yes, a patch committed by Masahiko Sawada on July 1, 2026 adds min() and max() aggregate support for uuid, using new uuid_larger() and uuid_smaller() support functions, since uuid already had a full set of comparison operators and a btree operator class making it totally ordered. This was authored by Tristan Partin. Values compare lexicographically over their 128 bits.

_Track PostgreSQL feature commits like uuid min/max aggregates on daily.dev before they land in a release._

### Why does min() and max() on UUIDv7 columns return the oldest and newest rows chronologically?

UUIDv7's most significant bits encode a Unix timestamp, so comparing UUIDv7 values lexicographically over their 128 bits coincides with chronological order. This means min(uuid_column) and max(uuid_column) on a column of UUIDv7 values return the oldest and newest generated values respectively, unlike random UUIDs (v4) where min/max carry no temporal meaning.

_Developers choosing between uuid versions for sortable primary keys can follow this kind of detail on daily.dev._

## Similar posts on daily.dev

- [The Time Traveler's Primary Key](https://daily.dev/posts/the-time-traveler-s-primary-key-x5yvsdpzm) · Planet PostgreSQL · 0 upvotes · 0 comments
- [PostgreSQL 18's UUIDv7: Faster and Secure Time-Ordered IDs](https://daily.dev/posts/postgresql-18-s-uuidv7-faster-and-secure-time-ordered-ids-smvesvjbw) · Hashrocket · 42 upvotes · 0 comments
- [Avoid UUID Version 4 Primary Keys](https://daily.dev/posts/avoid-uuid-version-4-primary-keys-5pot7xhqf) · Hacker News · 79 upvotes · 10 comments

---

Tags: [#sql](https://daily.dev/tags/sql), [#postgresql](https://daily.dev/tags/postgresql)

[View this post on daily.dev](https://daily.dev/posts/waiting-for-postgresql-20-add-min-and-max-aggregate-support-for-uuid-select-from-depesz--zwdjdsv2s)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Waiting for PostgreSQL 20 – Add min() and max() aggregate support for uuid. – select * from depesz;","url":"https://daily.dev/posts/waiting-for-postgresql-20-add-min-and-max-aggregate-support-for-uuid-select-from-depesz--zwdjdsv2s","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/waiting-for-postgresql-20-add-min-and-max-aggregate-support-for-uuid-select-from-depesz--zwdjdsv2s"},"datePublished":"2026-07-09T12:41:54.575Z","dateModified":"2026-09-14T08:51:42.622Z","description":"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,...","image":"https://media.daily.dev/image/upload/s--1KxV4ohY--/f_auto/v1722860400/public/Placeholder%2007","thumbnailUrl":"https://media.daily.dev/image/upload/s--1KxV4ohY--/f_auto/v1722860400/public/Placeholder%2007","isAccessibleForFree":true,"articleSection":"depesz","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"depesz","logo":"https://media.daily.dev/image/upload/s--ir7juGOi--/f_auto/v1758461024/logos/depesz","url":"https://daily.dev/sources/depesz"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/waiting-for-postgresql-20-add-min-and-max-aggregate-support-for-uuid-select-from-depesz--zwdjdsv2s","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":4},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"sql,postgresql","timeRequired":"PT3M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"depesz","item":"https://daily.dev/sources/depesz"},{"@type":"ListItem","position":3,"name":"Waiting for PostgreSQL 20 – Add min() and max() aggregate support for uuid. – select * from depesz;"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/waiting-for-postgresql-20-add-min-and-max-aggregate-support-for-uuid-select-from-depesz--zwdjdsv2s#faq","mainEntity":[{"@type":"Question","name":"Does PostgreSQL support min() and max() aggregate functions on uuid columns?","acceptedAnswer":{"@type":"Answer","text":"Yes, a patch committed by Masahiko Sawada on July 1, 2026 adds min() and max() aggregate support for uuid, using new uuid_larger() and uuid_smaller() support functions, since uuid already had a full set of comparison operators and a btree operator class making it totally ordered. This was authored by Tristan Partin. Values compare lexicographically over their 128 bits. Track PostgreSQL feature commits like uuid min/max aggregates on daily.dev before they land in a release."}},{"@type":"Question","name":"Why does min() and max() on UUIDv7 columns return the oldest and newest rows chronologically?","acceptedAnswer":{"@type":"Answer","text":"UUIDv7's most significant bits encode a Unix timestamp, so comparing UUIDv7 values lexicographically over their 128 bits coincides with chronological order. This means min(uuid_column) and max(uuid_column) on a column of UUIDv7 values return the oldest and newest generated values respectively, unlike random UUIDs (v4) where min/max carry no temporal meaning. Developers choosing between uuid versions for sortable primary keys can follow this kind of detail on daily.dev."}}]}
```

