Unclear guarantees about sort order on https://www.postgresql.org/docs/current/queries-order.html - Mailing list pgsql-docs

From PG Doc comments form
Subject Unclear guarantees about sort order on https://www.postgresql.org/docs/current/queries-order.html
Date
Msg-id 169642945128.656.17921924732262672146@wrigleys.postgresql.org
Whole thread Raw
Responses Re: Unclear guarantees about sort order on https://www.postgresql.org/docs/current/queries-order.html
List pgsql-docs
The following documentation comment has been logged on the website:

Page: https://www.postgresql.org/docs/16/queries-order.html
Description:

The document only says this about unsorted queries:

> After a query has produced an output table (after the select list has been
processed) it can optionally be sorted. If sorting is not chosen, the rows
will be returned in an unspecified order. The actual order in that case will
depend on the scan and join plan types and the order on disk, but it must
not be relied on. A particular output ordering can only be guaranteed if the
sort step is explicitly chosen.

It mentions "If sorting is not chosen". This sort of implies that if you
pick a sort the output order is predictable. However I believe that the only
actual guarantee is if the sort columns selected produce a unique value.

For example if you do `ORDER BY name` and have two rows with the same name I
don't think the order of those rows is predictable.

I think the docs should be updated to either:

1. Clearly state that the order **is** consent as long as any sort clause is
present, and specify what that order is.
2. Update the quoted sentence to refer to "If sorting is not chosen or the
sort columns do not form a unique key" instead of just "If sorting is not
chosen".

pgsql-docs by date:

Previous
From: Laurenz Albe
Date:
Subject: Re: unnest multirange, returned order
Next
From: PG Doc comments form
Date:
Subject: Missing closing ]