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 1k5vre-0000pD-OA for pgsql-general@arkaria.postgresql.org; Wed, 12 Aug 2020 18:52:42 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1k5vrd-0006LC-EI for pgsql-general@arkaria.postgresql.org; Wed, 12 Aug 2020 18:52:41 +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 1k5vrd-0006L5-69 for pgsql-general@lists.postgresql.org; Wed, 12 Aug 2020 18:52:41 +0000 Received: from n3.nabble.com ([162.255.23.22]) by makus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1k5vra-0005h9-Pl for pgsql-general@postgresql.org; Wed, 12 Aug 2020 18:52:40 +0000 Received: from n3.nabble.com (localhost [127.0.0.1]) by n3.nabble.com (Postfix) with ESMTP id 526A72053AF29 for ; Wed, 12 Aug 2020 11:52:37 -0700 (MST) Date: Wed, 12 Aug 2020 11:52:37 -0700 (MST) From: pinker To: pgsql-general@postgresql.org Message-ID: <1597258357335-0.post@n3.nabble.com> In-Reply-To: <8723a4ce-ee04-a52a-1ac7-eb4226b52712@aklaver.com> References: <1597242184038-0.post@n3.nabble.com> <8723a4ce-ee04-a52a-1ac7-eb4226b52712@aklaver.com> Subject: Re: insert on conflict postgres returning distinction MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk how about this solution? Does it have any caveats? WITH upsert AS (INSERT INTO GUCIO (ID, NAZWA) SELECT A.ID, A.NAZWA FROM ALA A ON CONFLICT (ID) DO UPDATE SET nazwa = excluded.nazwa RETURNING xmax,xmin, *) select xmax as xmax_value into txmaxu from upsert; delete from gucio where xmax = (select xmax_value from txmaxu where xmax_value <> 0 limit 1); -- Sent from: https://www.postgresql-archive.org/PostgreSQL-general-f1843780.html