From: Tom Lane <tgl@sss.pgh.pa.us>
To: David G. Johnston <david.g.johnston@gmail.com>
Cc: Dan Wainwright <danw.cobus@gmail.com>
Cc: PostgreSQL Documentation <pgsql-docs@lists.postgresql.org>
Subject: Re: RETURNING order guarantees documentation
Date: Sat, 04 May 2024 13:52:21 -0400
Message-ID: <2938693.1714845141@sss.pgh.pa.us> (raw)
In-Reply-To: <CAKFQuwbQqWHWdUDx+amZCZoQuK49R2EUS-npri2jBna4XRehPw@mail.gmail.com>
References: <CACTd0ws66eB=Nepy4nx3sr+fCdffVVgqd7KhYAxs+PR6HMo_=w@mail.gmail.com>
<CAKFQuwbQqWHWdUDx+amZCZoQuK49R2EUS-npri2jBna4XRehPw@mail.gmail.com>
"David G. Johnston" <david.g.johnston@gmail.com> writes:
> On Sat, May 4, 2024, 10:13 Dan Wainwright <danw.cobus@gmail.com> wrote:
>> 'Similar to' doesn't provide anything concrete to the reader. There was a thread
>> on [Hackers]
>> <https://www.mail-archive.com/pgsql-hackers@postgresql.org/msg253743.html;
>> back in 2015 proposing some docs to clearly explain that ordering is
>> preserved and I am keen to write the documentation if it's agreed to be
>> worth doing.
> Haven't reviewed the discussions recently but my understanding is that the
> lack of guarantee is correct and intentional. There is none.
Indeed. If you must have ordering you can do something like
with upd as (update foo set ... returning *)
select * from upd order by ...;
Otherwise it's going to be the order in which the rows were processed
by the ModifyTable node, which is intentionally unspecified.
The thread Dan refers to is here:
https://www.postgresql.org/message-id/flat/CAMsr%2BYEn5TOuhv_tTwY70S1zXf8jCQ-uixU8aOs4OQs7kojf6Q%40m...
and it doesn't seem to have gone anywhere. But I see that Craig
was really only concerned with whether INSERTs are processed in the
order returned by the data source, which is probably a pretty safe
assumption. Still, SQL is a set-oriented language which means that
it generally doesn't guarantee anything about row order, with the
sole exception being the immediate output of a SELECT ... ORDER BY.
So I think adding such guarantees isn't a great idea.
regards, tom lane
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: tgl@sss.pgh.pa.us, david.g.johnston@gmail.com, danw.cobus@gmail.com, pgsql-docs@lists.postgresql.org
Subject: Re: RETURNING order guarantees documentation
In-Reply-To: <2938693.1714845141@sss.pgh.pa.us>
* 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