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 1pmKGU-0006w0-So for pgsql-general@arkaria.postgresql.org; Tue, 11 Apr 2023 20:06:54 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pmKGT-0000W6-Ft for pgsql-general@arkaria.postgresql.org; Tue, 11 Apr 2023 20:06:53 +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 1pmKGT-0000Vx-5F for pgsql-general@lists.postgresql.org; Tue, 11 Apr 2023 20:06:53 +0000 Received: from out4-smtp.messagingengine.com ([66.111.4.28]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pmKGQ-0007a6-8M for pgsql-general@lists.postgresql.org; Tue, 11 Apr 2023 20:06:52 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id A1E955C00F7; Tue, 11 Apr 2023 16:06:46 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Tue, 11 Apr 2023 16:06:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to; s=fm2; t= 1681243606; x=1681330006; bh=iQcMhnp+gVPuUjS5+rRbwPOS4p+uiBvELuV JMwUvLLw=; b=XYG6B68SHcrcCc22vAmnBfLDkZv4QJ72PFQhDXc0i/le7pCnxV7 yhXKaOMCQ7VoUkmZKz/kBjNlFzGmrYlMMOqDWyQjyo4kDXb3dtCpdSL9E5x9gCfS OOTq++KGCZKvqaEOHpmalariO8mJCilUaPG3hylX8lLhsLqaUCMnz7Ltot0a2UIP A7EdSAtDB0RXSnHY6spbOLIwvllaSY6IrhFrIJWaNFWD/2Mzjx6NplasgYbewdY+ e8XIKtHAPW3TWtasZlgAtIOrlxW1giHAIWJ0PCzUfWpKgN0d2JEKht9cT5wbNGjT cJN4ybM2ptRTQis+8Xv/Cdzwp5nOQnxuO9Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1681243606; x=1681330006; bh=iQcMhnp+gVPuUjS5+rRbwPOS4p+uiBvELuV JMwUvLLw=; b=ctSOrltk6z8S+U1fVVmpOyKPBiv3lMtDg1cSReVeHYXSCFzKFKC CXp7+XNKOTM+T4f3nkUavt7fdl/RjMaedV9gywAEP73je7qMVIra7PYYBPeH4wFR GY0M8lHau2vQBHklZlj1aGecT7TdOEg4sROaZDVkWgiqrGIwi66SEcC35tbEJzO2 Gn7NhMLWOOGYNo5aFzYi8c3SFMEOH3zRSvsHESJ6WXnTw6Kqrm9HmFYQxSZ7aAYI H9ckW04xtqqH/yQUHa4oP8ta1BH0PmkaKjQBWv0zWQPht5vkUph2I0PbGj2nhDkk Ajbw3ycwUJZxfYpJL6SnGBt0sV6ZMaBERmA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrvdekgedgudegiecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecunecujfgurhepkfffgggfuffvvehfhfgjtgfgse htjeertddtfeejnecuhfhrohhmpeetughrihgrnhcumfhlrghvvghruceorggurhhirghn rdhklhgrvhgvrhesrghklhgrvhgvrhdrtghomheqnecuggftrfgrthhtvghrnhepfeekge evuedukeeutddvteegveeujeeghfdtveejieeuteehgeefjeejledtgeelnecuffhomhgr ihhnpehsqhhlihhtvgdrohhrghenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmh epmhgrihhlfhhrohhmpegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtohhm X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 11 Apr 2023 16:06:45 -0400 (EDT) Message-ID: <95fbd8c8-2f7a-38a1-4a41-b2ac3763d89c@aklaver.com> Date: Tue, 11 Apr 2023 13:06:45 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.9.1 Subject: Re: Guidance on INSERT RETURNING order Content-Language: en-US To: Federico , pgsql-general@lists.postgresql.org Cc: Mike Bayer References: From: Adrian Klaver In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 4/11/23 12:47, Federico wrote: > Hello list, > https://www.sqlite.org/lang_returning.html#limitations_and_caveats > > Searching the archive seems that a using the INSERT SELECT ORDER BY > form should be a better solution, > so the above insert should be rewritten as > > INSERT INTO t(data) > SELECT data FROM (VALUES ('a', 1), ('b', 2), ('c', 3)) as vv(data, > num) ORDER BY num > RETURNING id Or with i as (INSERT INTO t(data) VALUES ('a', 1), ('b', 2), ('c', 3) returning id) select i.id from i order by id; > Sorry for the long email, > Thanks > > Federico > > -- Adrian Klaver adrian.klaver@aklaver.com