Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hTSQ1-0004zS-5S for pgsql-general@arkaria.postgresql.org; Wed, 22 May 2019 14:40:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hTSPz-0005X8-RA for pgsql-general@arkaria.postgresql.org; Wed, 22 May 2019 14:40:35 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hTSPK-0000ao-3W for pgsql-general@lists.postgresql.org; Wed, 22 May 2019 14:39:54 +0000 Received: from out3-smtp.messagingengine.com ([66.111.4.27]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hTSPH-0007o6-6S for pgsql-general@postgresql.org; Wed, 22 May 2019 14:39:52 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 80C3924DDD; Wed, 22 May 2019 10:39:50 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Wed, 22 May 2019 10:39:50 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:cc:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm3; bh=+ 921tyx6S2QTrtbv0RxpuhxXzy/R+on3mbJwYJzCCBM=; b=bdO65U8z5EeAcypdl As0TJdKqSWBUsWuLKKrA6vq53OdiHDoTMOQ48Bk8H2BZfBv1XJJYnQkz0Jh1dRdJ 6Vvhbh3mqN0BldmLX2/fzYJNdZqJBJd7bLKx2zDVV76/PlIXbg9Adu8fWtvt+trG 2ubEJHjsFkKebxYyGSn0wiRo4issZQ4qYEwqo6CexgHAlNlQ72Z1rYs8x8mmaotL b4EfFbLHV2hK8i4gNrmIekL8vx6NG252Ik9GA6dQjrM2vskoIV6dq0XgTcbIxyzc TPFKHg/IE8eH0ZwGbSS8/6IlkaMw59cFi3A8Bxrr3m6Y7ZiwsxFsgm8E9tIHUbjm MuL8Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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=fm2; bh=+921tyx6S2QTrtbv0RxpuhxXzy/R+on3mbJwYJzCC BM=; b=yDwYrr0g6rKqAYbyZcQp2b7uIMrIN0ZeJVjzrhfKqZG9GafJAB8Y+Stv8 oR0KRoqBRZ74uEU/bdOGak/KpqJkHTKFADlqubsXWfpJJVfu0AkzKPLGmB9zHIKj dw8DL2zxNSWwA9fh4RVvz8vJdT6IaE6UTKuJQAiCkyLU4Bfu68tUE1of2XUL6LI3 mCwk5tX2886FG06IMdVBLPuREbisZYtoHBJ/4pqspJrjHsgoh0LY0Y1wfz6orcG8 pXWvXH7XEDXWudIrD7wXPhIR0d4203K8OOcMybAOQIalGcYx48ByI7twGTSDn+T3 3GYcJ4Ttz8bau0SuvPPVPkZQaKO6g== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduuddrudduvddgjeelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepuffvfhfhkffffgggjggtgfesthejredttdefjeenucfhrhhomheptegurhhi rghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtoh hmqeenucffohhmrghinhepphhoshhtghhrvghsqhhlrdhorhhgnecukfhppeejuddrvddu vddrudehtddrvddtvdenucfrrghrrghmpehmrghilhhfrhhomheprggurhhirghnrdhklh grvhgvrhesrghklhgrvhgvrhdrtghomhenucevlhhushhtvghrufhiiigvpedt X-ME-Proxy: Received: from [192.168.1.4] (unknown [71.212.150.202]) by mail.messagingengine.com (Postfix) with ESMTPA id 6520B380087; Wed, 22 May 2019 10:39:49 -0400 (EDT) Subject: Re: distinguish update from insert (on conflict) To: Justin Pryzby Cc: pgsql-general@postgresql.org References: <20190522013428.GG4426@telsasoft.com> <106c0789-7a13-7f9c-8d49-3562556bcdd8@aklaver.com> <20190522023748.GH4426@telsasoft.com> From: Adrian Klaver Message-ID: Date: Wed, 22 May 2019 07:39:48 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: <20190522023748.GH4426@telsasoft.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 5/21/19 7:37 PM, Justin Pryzby wrote: > On Tue, May 21, 2019 at 06:57:36PM -0700, Adrian Klaver wrote: >> On 5/21/19 6:34 PM, Justin Pryzby wrote: >>> Is it still impossible to distinguish whether a row was inserted vs updated ? >> >> You will need to be more specific. > > Sorry, I mean with UPSERT / "INSERT .. ON CONFLICT DO UPDATE", is it possible > to tell whether a row was inserted vs. updated ? In addition to Fabio's suggestion, from my previous post: https://www.postgresql.org/docs/10/sql-createtrigger.html "n some cases it is possible for a single SQL command to fire more than one kind of trigger. For instance an INSERT with an ON CONFLICT DO UPDATE clause may cause both insert and update operations, so it will fire both kinds of triggers as needed. The transition relations supplied to triggers are specific to their event type; thus an INSERT trigger will see only the inserted rows, while an UPDATE trigger will see only the updated rows." So you might want to check out triggers using transition tables. > > Thanks, > Justin > -- Adrian Klaver adrian.klaver@aklaver.com