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 1pcnNR-0007OG-HY for pgsql-bugs@arkaria.postgresql.org; Thu, 16 Mar 2023 13:10:41 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pcnNP-0004KM-62 for pgsql-bugs@arkaria.postgresql.org; Thu, 16 Mar 2023 13:10:39 +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 1pcnNO-0004JD-U3 for pgsql-bugs@lists.postgresql.org; Thu, 16 Mar 2023 13:10:38 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pcnNM-0008AM-Iu for pgsql-bugs@lists.postgresql.org; Thu, 16 Mar 2023 13:10:38 +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 32GDAQAp3759408; Thu, 16 Mar 2023 09:10:27 -0400 From: Tom Lane To: "David G. Johnston" cc: "digoal@126.com" , "pgsql-bugs@lists.postgresql.org" Subject: Re: BUG #17845: insert into on conflict bug . In-reply-to: References: <17845-fee889ae7e226a76@postgresql.org> Comments: In-reply-to "David G. Johnston" message dated "Thu, 16 Mar 2023 05:22:23 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <3759406.1678972226.1@sss.pgh.pa.us> Content-Transfer-Encoding: 8bit Date: Thu, 16 Mar 2023 09:10:26 -0400 Message-ID: <3759407.1678972226@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 Thursday, March 16, 2023, PG Bug reporting form > wrote: >> In the following insert statement, the row has not been updated multiple >> times, why is it still showing an error? >> insert into a >> select * from (values (1,'a',date '2022-01-01'),(1,'b',date >> '2022-01-02'),(1,'c',date '2022-01-03')) as t (id,info,ts) order by ts >> desc >> on conflict (id) >> do update set info=excluded.info, ts=excluded.ts where a.ts < excluded.ts >> ; > You have id=1 in there three times which is precisely the definition of > “multiple times” (I.e., more than 1) Yeah. I believe the reason for the restriction is that it would otherwise be very uncertain what order the input rows get processed in. (No, the "order by" won't save you, because there's still a join to be done after that.) regards, tom lane