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 1pmit2-0005uV-BL for pgsql-general@arkaria.postgresql.org; Wed, 12 Apr 2023 22:24:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pmit1-0007fu-AG for pgsql-general@arkaria.postgresql.org; Wed, 12 Apr 2023 22:24:19 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pmit0-0007fV-W6 for pgsql-general@lists.postgresql.org; Wed, 12 Apr 2023 22:24:18 +0000 Received: from evolvis.org ([2a02:a00:2000:f::1]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1pmisy-002WVB-97 for pgsql-general@lists.postgresql.org; Wed, 12 Apr 2023 22:24:18 +0000 Received: from x61w.mirbsd.org (xdsl-78-35-165-237.nc.de [78.35.165.237]) (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 9DCDB100955; Wed, 12 Apr 2023 22:24:14 +0000 (UTC) Received: by x61w.mirbsd.org (Postfix, from userid 1000) id A57E6608E4; Thu, 13 Apr 2023 00:24:13 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by x61w.mirbsd.org (Postfix) with ESMTP id 9F56460586; Thu, 13 Apr 2023 00:24:13 +0200 (CEST) Date: Thu, 13 Apr 2023 00:24:13 +0200 (CEST) From: Thorsten Glaser To: Kirk Wolak cc: pgsql-general@lists.postgresql.org Subject: Re: Guidance on INSERT RETURNING order In-Reply-To: Message-ID: References: <95fbd8c8-2f7a-38a1-4a41-b2ac3763d89c@aklaver.com> 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 Wed, 12 Apr 2023, Kirk Wolak wrote: >The solution exists. Pre-fetch the IDs, assign them and insert them with >the IDs. Then you have 100% control. >SELECT NEXTVAL('tbl_seq') from GENERATE_SERIES(1, ); This would be a nice solution=E2=80=A6 but the PK could be always generated= , or not even sequential (UUIDs for example). If you=E2=80=99re developing schema-first the application would not even (need to) know about how the IDs are generated as it=E2=80=99s the DB that generates them. AIUI the OP=E2=80=99s an SQLAlchemy developer, which is an ORM. Therefore h= e needs a generic solution. bye, //mirabilos --=20 15:41=E2=8E=9C Somebody write a testsuite for hello= world :-)