Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pmMMM-0005BA-VR for pgsql-general@arkaria.postgresql.org; Tue, 11 Apr 2023 22:21:06 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pmMML-000866-RM for pgsql-general@arkaria.postgresql.org; Tue, 11 Apr 2023 22:21:05 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pmMML-00085v-Gt for pgsql-general@lists.postgresql.org; Tue, 11 Apr 2023 22:21:05 +0000 Received: from evolvis.org ([2a02:a00:2000:f::1]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pmMMH-0000N6-Nk for pgsql-general@lists.postgresql.org; Tue, 11 Apr 2023 22:21:04 +0000 Received: from x61w.mirbsd.org (2001-4dd7-f42e-0-21f-3bff-fe0d-cbb1.ipv6dyn.netcologne.de [IPv6:2001:4dd7:f42e:0:21f:3bff:fe0d:cbb1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (Client did not present a certificate) by evolvis.org (Postfix) with ESMTPSA id 1E248100955 for ; Tue, 11 Apr 2023 22:20:59 +0000 (UTC) Received: by x61w.mirbsd.org (Postfix, from userid 1000) id D5DD1613D2; Wed, 12 Apr 2023 00:20:56 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by x61w.mirbsd.org (Postfix) with ESMTP id D0B90602E4 for ; Wed, 12 Apr 2023 00:20:56 +0200 (CEST) Date: Wed, 12 Apr 2023 00:20:56 +0200 (CEST) From: Thorsten Glaser To: pgsql-general@lists.postgresql.org Subject: Re: Guidance on INSERT RETURNING order In-Reply-To: Message-ID: <2b8d529a-0ec-4e8f-26d3-2ef2881a2d49@evolvis.org> References: <95fbd8c8-2f7a-38a1-4a41-b2ac3763d89c@aklaver.com> <3b1117cc-fe46-1ca0-d0f-92304c6fc79@evolvis.org> <8a57a79b-6e73-99b4-8f3a-859fccb5eb3b@evolvis.org> Content-Language: de-DE-1901 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: QUOTED-PRINTABLE List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, 11 Apr 2023, Federico wrote: >My understanding was that they are generated in select order But are they? (I don=E2=80=99t know, but I=E2=80=99d not assume that.) >If my understanding is incorrect, would this alternative guarantee the abo= ve > INSERT INTO t(id, data) > SELECT nextval(pg_get_serial_sequence('t', 'id')) data > FROM (VALUES ('a', 1), ('b', 2), ('c', 3)) as vv(data, num) > ORDER BY num > RETURNING id Wouldn=E2=80=99t, at that point, it be better to just send multiple individual INSERT statements? The overhead (on both sides) for all mentioned=E2=80=A6 workarounds=E2=80=A6 surely is larger than that? bye, //mirabilos --=20 15:41=E2=8E=9C Somebody write a testsuite for hello= world :-)