Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1s3JYi-00BkQv-B7 for pgsql-docs@arkaria.postgresql.org; Sat, 04 May 2024 17:52:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1s3JYf-001Eur-Ne for pgsql-docs@arkaria.postgresql.org; Sat, 04 May 2024 17:52:26 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1s3JYf-001EsF-A8 for pgsql-docs@lists.postgresql.org; Sat, 04 May 2024 17:52:26 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1s3JYd-001RKa-GF for pgsql-docs@lists.postgresql.org; Sat, 04 May 2024 17:52:24 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 444HqLC72938694; Sat, 4 May 2024 13:52:21 -0400 From: Tom Lane To: "David G. Johnston" cc: Dan Wainwright , PostgreSQL Documentation Subject: Re: RETURNING order guarantees documentation In-reply-to: References: Comments: In-reply-to "David G. Johnston" message dated "Sat, 04 May 2024 10:29:04 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2938692.1714845141.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Sat, 04 May 2024 13:52:21 -0400 Message-ID: <2938693.1714845141@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk "David G. Johnston" writes: > On Sat, May 4, 2024, 10:13 Dan Wainwright wrote: >> 'Similar to' doesn't provide anything concrete to the reader. There was= a thread >> on [Hackers] >> >> 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 t= he > 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_tTwY70S1zXf8j= CQ-uixU8aOs4OQs7kojf6Q%40mail.gmail.com 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