Re: Suggestion. Optional local ORDER BY clause for DISTINCT ON - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Suggestion. Optional local ORDER BY clause for DISTINCT ON
Date
Msg-id 432142.1696962563@sss.pgh.pa.us
Whole thread Raw
In response to Suggestion. Optional local ORDER BY clause for DISTINCT ON  (Stefan Stefanov <stefanov.sm@abv.bg>)
List pgsql-hackers
Stefan Stefanov <stefanov.sm@abv.bg> writes:
>  Gents, I have a suggestion for DISTINCT ON clause syntax.
>    DISTINCT ON (expression(s) [ORDER BY expression(s)])
> Determines the precedence within each DISTINCT ON group (i.e. the ‘first’ row to be picked)

> Motivation
> • Using the query-wide ORDER BY clause to determine which record to pick mixes two unrelated concerns, ‘first’ row
selectionand result-set ordering. This may be confusing; 
> • The DISTINCT ON expression(s) must match the leftmost ORDER BY expression(s). This may cause inconvenience and
requirenesting as a sub-query to order the result-set. 

Since you can get the desired behavior with a sub-select, I'm
not especially excited about extending DISTINCT ON.  If it weren't
such a nonstandard kluge, I might feel differently; but it's not
an area that I think we ought to put more effort into.

            regards, tom lane



pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: Check each of base restriction clauses for constant-FALSE-or-NULL
Next
From: Robert Haas
Date:
Subject: Re: New WAL record to detect the checkpoint redo location