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 1hTNfX-0006lp-Va for pgsql-general@arkaria.postgresql.org; Wed, 22 May 2019 09:36:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hTNfV-0007zk-U0 for pgsql-general@arkaria.postgresql.org; Wed, 22 May 2019 09:36:17 +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 1hTNfV-0007zd-Ew for pgsql-general@lists.postgresql.org; Wed, 22 May 2019 09:36:17 +0000 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hTNfT-00019x-3R for pgsql-general@postgresql.org; Wed, 22 May 2019 09:36:16 +0000 Received: by mail-wm1-x32c.google.com with SMTP id x64so1457458wmb.5 for ; Wed, 22 May 2019 02:36:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ocado.com; s=google; h=reply-to:subject:to:cc:references:from:organization:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=7/vLiI7+AyFvoNJojqEE2qOyKowACiezbPDs6IMB9tI=; b=AxnUDZupK5B7eVJKCAAVgQeyaefbyHh6sSqFlJ9ja0fx5LqxEPCYH5b4bUSO+g90lu 4ZtbVfQX3kzcCjhScW5a0YsAWPCt1m6d1oqsArQRC1l9gH7E+rOk32Ai1PvM7kPv/HUW /j1El7j/4BBEFakZGKEAGvlu8UDk1pw/pXLWHgVw/lwUScdTZXIXEik9kSX9ARcg+1jI olnH37P7oWzns8abFp/mZjRQbVARRw6SlT87t/Q2hJR/mC8K9XF9suOsWS1prRLmthfm YyP7oLAngM+fnS0Xr6OwRFZktJq8PsCYTorh8G/nZviRE+e5eq4naFd6eUOv68IppoPw luHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:reply-to:subject:to:cc:references:from :organization:message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=7/vLiI7+AyFvoNJojqEE2qOyKowACiezbPDs6IMB9tI=; b=NZGx+zcwiVQQkJoVdgINNc7T0d5StbzZiCuq3ad8uF7SC9oJpygpveUUB1J1+VBezu PLtMiFJZLAjdgg2ZngCCTpuQj8STAxrFymD5fRbt6UvNLkLihY5uKac7A65+s29TQVXb GfoVRdjFS9UxHt3iR0L1AlxOVF2hc6nrqO5e3rngSvUb2QlliZYa+FPD1YKWD5k4NS6S wuKxyKN5AXMKECMQmnIq1XIuCOX5pPIzyevpBEMxJsKDZzkn7bJT72wzcO+MvIC9lENQ UKc9cnFs0RNzyN+3w/jtudeQFK6k4NW7m855+lEPFA2+rHFz/5D69J1K7iHki9K/asvI aAMg== X-Gm-Message-State: APjAAAX5nn0K1Foi/9QrkxPbdAMnlHW4RThbYDNh3zFTJbCc8gBhBh48 z8NUj2NIKw3u20X6UPCtabo0qooB4hoXXRFsMGJ97PoasBbb5bKXPC1NGtCEzjgWs/xf2OgmtT+ 0i8bnFLrbMSjU8WObgN1Egg== X-Google-Smtp-Source: APXvYqzn2pdpSoBKVe8kEksArJlL29S2HsMhBDOVp6j/jxHfl7zWKvjIrpKIB/VQfptI5+nyfBkg0Q== X-Received: by 2002:a1c:2dd2:: with SMTP id t201mr6642465wmt.136.1558517773176; Wed, 22 May 2019 02:36:13 -0700 (PDT) Received: from [10.62.14.40] ([91.206.0.63]) by smtp.gmail.com with ESMTPSA id 6sm30079918wrd.51.2019.05.22.02.36.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 May 2019 02:36:11 -0700 (PDT) Reply-To: f.venchiarutti@ocado.com Subject: Re: distinguish update from insert (on conflict) To: Justin Pryzby , Adrian Klaver Cc: pgsql-general@postgresql.org References: <20190522013428.GG4426@telsasoft.com> <106c0789-7a13-7f9c-8d49-3562556bcdd8@aklaver.com> <20190522023748.GH4426@telsasoft.com> From: Fabio Ugo Venchiarutti Organization: Ocado Technology Message-ID: Date: Wed, 22 May 2019 10:36:10 +0100 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: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 22/05/2019 03:37, 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 upd= ated ? >> >> You will need to be more specific. >=20 > Sorry, I mean with UPSERT / "INSERT .. ON CONFLICT DO UPDATE", is it poss= ible > to tell whether a row was inserted vs. updated ? >=20 > Thanks, > Justin >=20 >=20 Here's my recipe for that: RETURNING /* whatever, */ (xmax =3D 0) AS is_new_record ; I don't know if any of the hackers thought of a sleeker technique --=20 Regards Fabio Ugo Venchiarutti OSPCFC Network Engineering Dpt. Ocado Technology --=20 Notice: =C2=A0This email is confidential and may contain copyright material= of=20 members of the Ocado Group. Opinions and views expressed in this message=20 may not necessarily reflect the opinions and views of the members of the=20 Ocado Group.=C2=A0 =C2=A0 If you are not the intended recipient, please notify us=20 immediately and delete all copies of this message. Please note that it is= =20 your responsibility to scan this message for viruses.=C2=A0 =C2=A0 Fetch and Sizzle=20 are trading names of Speciality Stores Limited and Fabled is a trading name= =20 of Marie Claire Beauty Limited, both members of the Ocado Group. =C2=A0 References to the =E2=80=9COcado Group=E2=80=9D are to Ocado Group plc (reg= istered in=20 England and Wales with number 7098618) and its subsidiary undertakings (as= =20 that expression is defined in the Companies Act 2006) from time to time. = =C2=A0 The registered office of Ocado Group plc is=C2=A0Buildings One & Two, Tride= nt=20 Place, Mosquito Way, Hatfield, Hertfordshire, AL10 9UL.