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: ANSI SQL proposal: SELECT DISTINCT ON (... ORDER BY ...) and UNION DISTINCT ON (... ORDER BY ...)
Date: 2026-08-01 13:08:48
Message-ID: CAMT0RQR_QqLqKdLgh3zYk7yA7oH9RJBVF+kZJ607wjJD9WKH9Q@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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
xxx000-distinct-on-clause.md text/markdown 8.4 KB

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Geoghegan 2026-08-01 15:01:52 GiST multirange index scans can fail to return rows
Previous Message Chengpeng Yan 2026-08-01 09:38:43 Re: a large LIMIT makes some sorts slower