From: PG Doc comments form <noreply@postgresql.org>
To: pgsql-docs@lists.postgresql.org
Cc: www.postgresql.org-33da24d6@kevincox.ca
Subject: Unclear guarantees about sort order on https://www.postgresql.org/docs/current/queries-order.html
Date: Wed, 04 Oct 2023 14:24:11 +0000
Message-ID: <169642945128.656.17921924732262672146@wrigleys.postgresql.org> (raw)
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".
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-docs@postgresql.org
Cc: noreply@postgresql.org, pgsql-docs@lists.postgresql.org, www.postgresql.org-33da24d6@kevincox.ca
Subject: Re: Unclear guarantees about sort order on https://www.postgresql.org/docs/current/queries-order.html
In-Reply-To: <169642945128.656.17921924732262672146@wrigleys.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox