Re: ANSI SQL proposal: SELECT DISTINCT ON (... ORDER BY ...) and UNION DISTINCT ON (... ORDER BY ...)

From: Hannu Krosing <hannuk(at)google(dot)com>
To: Vik Fearing <vik(at)postgresfriends(dot)org>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>, Peter Eisentraut <peter(at)eisentraut(dot)org>, Dilip Kumar <dilipkumarb(at)google(dot)com>
Subject: Re: ANSI SQL proposal: SELECT DISTINCT ON (... ORDER BY ...) and UNION DISTINCT ON (... ORDER BY ...)
Date: 2026-09-16 15:15:41
Message-ID: CAMT0RQRL7cqpKHMsRd0cCjDQMRHonv3aW5Pj5NH3G=52MfYVew@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Here is a patch set implementing this

On Sat, Aug 1, 2026 at 3:08 PM Hannu Krosing <hannuk(at)google(dot)com> wrote:

> Hi Vik
>
> Finally had time to put this SQL Standard Propoasl together.
>
> Please take a quick look and tell me what is missing or wrong and what
> the next steps should be.
>
> For example, should I mention somewhere that PostgreSQL supports a
> partial version of the SELECT DISTINCT ON () ?
>
> Regarding PGQ in PostgreSQL, this should allow a plain SQL target for
> arbitrary length graph queries and at least some types of path finding
> queries.
>
> I hope to have some working PoC code for PostgreSQL within the next
> few days so I can share actual working versions of both sample
> recursive graph queries and the "overlay of read-only table" queries I
> talked to you about.
>
> -----
> Hannu
>

Attachment Content-Type Size
0001-Refactor-set-operation-group-clauses-to-decouple-fro.patch application/x-patch 9.7 KB
0003-Support-UNION-DISTINCT-ON-for-non-recursive-set-oper.patch application/x-patch 22.1 KB
0004-Support-dynamic-pruning-in-recursive-UNION-DISTINCT-.patch application/x-patch 17.7 KB
0002-Support-inline-ORDER-BY-in-DISTINCT-ON-for-SELECT-an.patch application/x-patch 28.9 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Sami Imseih 2026-09-16 15:30:44 Re: Track skipped tables during autovacuum and autoanalyze
Previous Message Atsushi Ogawa 2026-09-16 15:10:26 Re: [PATCH] Use Boyer-Moore-Horspool for simple LIKE contains patterns