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 1k5tBs-0001v1-EA for pgsql-general@arkaria.postgresql.org; Wed, 12 Aug 2020 16:01:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1k5tBr-0007L4-DC for pgsql-general@arkaria.postgresql.org; Wed, 12 Aug 2020 16:01:23 +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 1k5tBp-0007Kv-PZ for pgsql-general@lists.postgresql.org; Wed, 12 Aug 2020 16:01:23 +0000 Received: from [66.111.4.27] (helo=out3-smtp.messagingengine.com) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1k5tBm-0004FC-Pv for pgsql-general@postgresql.org; Wed, 12 Aug 2020 16:01:20 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id C74C35C018E; Wed, 12 Aug 2020 12:01:07 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Wed, 12 Aug 2020 12:01:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm3; bh=r ItSEYlzbQvqxtWKkPOSMFfsxnyTcBH2T1n4XSxCSIM=; b=OzihARhqZv6ituUlV /wBdLeWs/c+ePaNAoT8Cm0IsCXDC8elypBenvoSB44PniYDg+at343YuD0g1OR9c 8v7ne/IHHZTyIMBU4IEMBUf/H6CNkfgs9Qb6gOHi0oLoL5rHuOwWcoHP3AlOcXbT 6JhltoQQEFidhnPgAR1MrMjFgHaeBsqWe1wN9InUZ4gbucP3ZsU9Xbj1SLnHikTB 8j764AyxBoU9wmQeaYlFeGQJsV+VHFbOloJ8izJ1O7n2m/bvMmRi+q1aDRumARet 5kpkv+oa2VRae1XMMZmWB4C2Q7st0KIYnG62v6R+xK7mKCLnamlf4sNWguiZj5hW /jVYg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; bh=rItSEYlzbQvqxtWKkPOSMFfsxnyTcBH2T1n4XSxCS IM=; b=p6Rqtw1RrP/0UnogM3VdPByeIY3UGgskk+Q+GT0PyPOE0pltIOnG2DzBa ezcMjSZ7A6g7DHQIUSzzTE4B3Wjp65tnFnXytcBe1xeojvUoAiilZffPpA8ftvls vMFeMGWvSkmLX6NiSY43legmKaWyvlEsH02L6sKjqiRRerACZHn3R7btSzU7aWAa 2J2Rcn75a+2/XXmO02jo6EkCejOBatdBDQSzpJv/oJ8VHnNV1WOb7nHPj7GbZkV4 ryARz0uUoY2D+L+Kb8oxjLFlnvsCQlV9znX/DXLy6ZsYyey4Rmb1AdtDlhFc8e8l er/rv/cub4a1VdU9NJEcSNbXLIQlQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduiedrledvgdelhecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepuffvfhfhkffffgggjggtgfesthejre dttdefjeenucfhrhhomheptegurhhirghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhl rghvvghrsegrkhhlrghvvghrrdgtohhmqeenucggtffrrghtthgvrhhnpefgkeffjeeiff etleejgeegteetffeivdeltedtkedvgfekjeffveekueehkeefteenucffohhmrghinhep phhoshhtghhrvghsqhhlrdhorhhgpdhpohhsthhgrhgvshhqlhdqrghrtghhihhvvgdroh hrghenucfkphepjeehrddujedvrdehrddvfedunecuvehluhhsthgvrhfuihiivgeptden ucfrrghrrghmpehmrghilhhfrhhomheprggurhhirghnrdhklhgrvhgvrhesrghklhgrvh gvrhdrtghomh X-ME-Proxy: Received: from [192.168.1.3] (75-172-5-231.tukw.qwest.net [75.172.5.231]) by mail.messagingengine.com (Postfix) with ESMTPA id 34CB53280063; Wed, 12 Aug 2020 12:01:07 -0400 (EDT) Subject: Re: insert on conflict postgres returning distinction To: pinker , pgsql-general@postgresql.org References: <1597242184038-0.post@n3.nabble.com> From: Adrian Klaver Message-ID: <8723a4ce-ee04-a52a-1ac7-eb4226b52712@aklaver.com> Date: Wed, 12 Aug 2020 09:01:06 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.11.0 MIME-Version: 1.0 In-Reply-To: <1597242184038-0.post@n3.nabble.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Host-Lookup-Failed: Reverse DNS lookup failed for 66.111.4.27 (deferred) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 8/12/20 7:23 AM, pinker wrote: > is there any way to distinct between updated and inserted rows in RETURNING > clause when ON CONFLICT UPDATE was used? Do you want to use that information immediately in the query or store it somewhere? If the first case I don't think that is possible. For the second then, I haven't tried it but, maybe a trigger using transition tables per example here: https://www.postgresql.org/docs/12/plpgsql-trigger.html Example 42.7. Auditing with Transition Tables > > > > -- > Sent from: https://www.postgresql-archive.org/PostgreSQL-general-f1843780.html > > -- Adrian Klaver adrian.klaver@aklaver.com