Re: sorting problem with distinct on() - Mailing list pgsql-general

From Tom Lane
Subject Re: sorting problem with distinct on()
Date
Msg-id 3585863.1683296778@sss.pgh.pa.us
Whole thread Raw
In response to Re: sorting problem with distinct on()  ("David G. Johnston" <david.g.johnston@gmail.com>)
List pgsql-general
"David G. Johnston" <david.g.johnston@gmail.com> writes:
> On Fri, May 5, 2023 at 6:55 AM Sky Lendar <skylendar@gmail.com> wrote:
>> Notice that 12 is missing in the list.

> Since your DISTINCT ON *subquery* doesn't specify an ordering which of
> those two are chosen as the representative record for M31 is
> non-determinstic.

> If you want to ensure the lowest valued nb is chosen you need to sort the
> *subquery*.

The "weather_reports" example here might help clarify this for you:

https://www.postgresql.org/docs/current/sql-select.html

            regards, tom lane



pgsql-general by date:

Previous
From: Sky Lendar
Date:
Subject: Re: sorting problem with distinct on()
Next
From: Adrian Klaver
Date:
Subject: Re: SSL Enablement in Postgres via Client App like PG-ADMIN-4, Java.