Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ayo40-0006d1-3P for pgsql-bugs@arkaria.postgresql.org; Fri, 06 May 2016 22:17:36 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1ayo3z-000209-39 for pgsql-bugs@arkaria.postgresql.org; Fri, 06 May 2016 22:17:35 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1aym1F-0006Gi-9w for pgsql-bugs@postgresql.org; Fri, 06 May 2016 20:06:37 +0000 Received: from mail-io0-x22b.google.com ([2607:f8b0:4001:c06::22b]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1aym1B-0002Q1-5u for pgsql-bugs@postgresql.org; Fri, 06 May 2016 20:06:36 +0000 Received: by mail-io0-x22b.google.com with SMTP id f89so124348751ioi.0 for ; Fri, 06 May 2016 13:06:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=salesintel.com; s=google; h=message-id:mime-version:to:cc:from:subject:date:importance :in-reply-to:references; bh=nvwj8rr5lAYcRTj+28xcOp8GpHUPXt+UR1N6k1zPgnA=; b=bI9GxHZqVnFDJm7eUDCwp+A+e3oBF/a3sgaAsNNahpNhsjPgMQSnGe9Gy5525neWwn Wu4pMN8DLpfOV049nX0KoEsJy3GL/GpzrPMH+keIeEAh7HhfCgYJ5CHKfkL5Yfpda4gh oDoPFWR0DYSWxBS265gw8PmFnbWrYZjmI1eB4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:mime-version:to:cc:from:subject:date :importance:in-reply-to:references; bh=nvwj8rr5lAYcRTj+28xcOp8GpHUPXt+UR1N6k1zPgnA=; b=MU9W7SbJHqQCSHCeCUskoc7k8hb3/TiGfPh8SPHMIIxnKnhjFVlcwFpctp7c8cY6m6 wLeH6VL4AJiWr+KzAcghHAKwXL0kNftlo8mx6+cuecld2Q15nOmA2I/tBdDc3eXgRpDq LeHyZqLsmhhiKqZc90KwfM932HMB7nqH/sdLGECO6Q8FftiT5gAwMTXLyK91lRUHCvf0 Tp2GSJvBs/tkgZhFg/cCTVlvcAzBhvISJZ02yTbMGPuYjuyFGChg8dWBVFdmgbMxig9X XxIZ9ph0IBRhXF29gsW/VJVxsgj3LJtovKQNEJce4a41bThVpzhquGXj5zDgDlFWFxWW ACmg== X-Gm-Message-State: AOPr4FW3qgK7VdKlT+05p5bABhb/DlGQm0qdvJ+b/Xkh75LKwGkotDd9I1ERmNGuf/Vujw== X-Received: by 10.107.19.148 with SMTP id 20mr28490723iot.11.1462565191226; Fri, 06 May 2016 13:06:31 -0700 (PDT) Received: from ?IPv6:::ffff:192.168.1.5? (75-171-210-80.hlrn.qwest.net. [75.171.210.80]) by smtp.gmail.com with ESMTPSA id vu8sm4959860igb.1.2016.05.06.13.06.29 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 06 May 2016 13:06:30 -0700 (PDT) Message-ID: <572cf946.489b320a.429be.ffffd369@mx.google.com> MIME-Version: 1.0 To: "David G. Johnston" Cc: Andres Freund , Peter Geoghegan , pgsql-bugs From: Paul Subject: Re: BUG #13846: INSERT ON CONFLICTconsumessequencersonconflicts Date: Fri, 6 May 2016 14:06:18 -0600 Importance: normal X-Priority: 3 In-Reply-To: References: <20160105150227.1117.51692@wrigleys.postgresql.org> <20160105161326.GD7650@awork2.anarazel.de> <20160106181946.GE7650@awork2.anarazel.de> <568d8060.291cb60a.e8a06.ffff9d00@mx.google.com> <568d8e74.d1a9ca0a.d9558.ffff9026@mx.google.com> <20160106221130.GG7650@awork2.anarazel.de> <568dadd1.42beca0a.8c605.fffff6eb@mx.google.com> Content-Type: multipart/alternative; boundary="_2E708437-EAD2-47D7-973A-1431FADE94A2_" X-Pg-Spam-Score: -2.7 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org --_2E708437-EAD2-47D7-973A-1431FADE94A2_ Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Hi Dave,=20 Thanks for the informative reply. We absolutely agree it=E2=80=99s not a bu= g in implementation, but maybe a bug in conceptualization with regard to us= ability. Not knowing the initial motive for the feature, we assumed it was = meant for an intuitively simpler form of the rather common upsert pattern, = but it seems INSERT ON CONFLICT was meant for some other purpose that we do= n=E2=80=99t quite understand. We stopped using and went back to a manual ap= proach, which also works great because PostgreSQL is just kinda great =F0= =9F=98=8A. If any related enhancements where to be done, our =E2=80=98holy grail=E2=80= =99 would be an implementation of the MERGE statement, like this, or this, = or this=E2=80=A6 We can at least ask for it right?? =F0=9F=98=89 Thanks for all your guys=E2=80=99 hard work -p From: David G. Johnston Sent: Friday, May 6, 2016 1:02 PM To: Paul Cc: Andres Freund; Peter Geoghegan; pgsql-bugs Subject: Re: [BUGS] BUG #13846: INSERT ON CONFLICTconsumessequencersonconfl= icts On Wed, Jan 6, 2016 at 5:14 PM, Paul wrote: If I had a BEFORE INSERT trigger, it would only execute for records that we= re actually going to be inserted. However, you=E2=80=99re now stating that = the INSERT ON CONFLICT will execute a BEFORE INSERT trigger even for record= s that are not inserted?? That doesn=E2=80=99t seem quite logical, and cont= rary to =E2=80=98old fashioned=E2=80=99 upsert logic. Does this also mean t= hat the BEFORE UPDATE trigger is always called as well, or is it never call= ed? =E2=80=8BThis seems to boil down to the two possible ways of manually imple= menting UPSERT: UPDATE, if not present, INSERT INSERT, if failing, UPDATE In the later the before insert trigger fires and influences whether the ins= ert=E2=80=8B =C2=A0 =E2=80=8Bfails.=C2=A0 In the former you are already pretty certain the inse= rt will =E2=80=8Bsucceed because the UPDATE found no records. We've implemented INSERT, if failing UPDATE.=C2=A0 The insert has to be att= empted and right now there is no concept of targeted partial deferrability = when constructing the record to be inserted. To solve this situation it is likely that some form of "UPDATE ON MISSING I= NSERT" would need to be designed.=C2=A0 The insert portion would specify "D= EFAULT" for sequence columns and would execute nextval() only if the ON MIS= SING portion is executed. Fundamentally, the difference is that ON MISSING is considerably less compl= icated than ON CONFLICT.=C2=A0 What is wanted here is an ON MISSING interpr= etation but what we've implemented is ON CONFLICT.=C2=A0 It seems that the = hackers are in agreement that our implementation of ON CONFLICT is consiste= nt with its definition.=C2=A0 That it doesn't efficiently solve problems be= tter handled by ON MISSING - while unfortunate - doesn't constitute a bug: = only an opportunity for future enhancement. David J. =E2=80=8B --_2E708437-EAD2-47D7-973A-1431FADE94A2_ Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset="utf-8"

Hi Dave,

Th= anks for the informative reply. We absolutely agree it=E2=80=99s not a bug = in implementation, but maybe a bug in conceptualization with regard to usab= ility. Not knowing the initial motive for the feature, we assumed it was me= ant for an intuitively simpler form of the rather common upsert pattern, bu= t it seems INSERT ON CONFLICT was meant for some other purpose that we don= =E2=80=99t quite understand. We stopped using and went back to a manual app= roach, which also works great because PostgreSQL is just kinda great 😊.

 

If any related e= nhancements where to be done, our =E2=80=98holy grail=E2=80=99 would be an = implementation of the MERGE statement, like this, or this, or this=E2=80=A6 We ca= n at least ask for it right?? 😉

 

Thanks for all your guys=E2=80=99 hard work

 

-p

 

From: David G. Johnston
Sent: Friday= , May 6, 2016 1:02 PM
To: = Paul
Cc: Andres Freund<= /a>; Peter Geoghegan; pgsql-bugs
Subject: Re: [BUGS] B= UG #13846: INSERT ON CONFLICTconsumessequencersonconflicts

 

On Wed, Jan 6, 2016= at 5:14 PM, Paul <paul@salesintel.com> wrote:

= If I had a BEFORE INSERT trigger, it would only execute for records that we= re actually going to be inserted. However, you=E2=80=99re now stating that = the INSERT ON CONFLICT will execute a BEFORE INSERT trigger even for record= s that are not inserted?? That doesn=E2=80=99t seem quite logical, and cont= rary to =E2=80=98old fashioned=E2=80=99 upsert logic. Does this also mean t= hat the BEFORE UPDATE trigger is always called as well, or is it never call= ed?

 =

=E2=80=8BThis seems to boil down to th= e two possible ways of manually implementing UPSERT:

<= /div>

 

UPDATE, if not present, INSERT

<= /div>

INSERT, if failing, UPDATE

 

=

In the later the before insert trigger fires and influences = whether the insert=E2=80=8B

 = ;=E2=80=8Bfails.  In the former = you are already pretty certain the insert will =E2=80=8Bsucceed because the= UPDATE found no records.

 

= We've imple= mented INSERT, if failing UPDATE.  The insert has to be attempted and = right now there is no concept of targeted partial deferrability when constr= ucting the record to be inserted.

 

To solve = this situation it is likely that some form of "UPDATE ON MISSING INSER= T" would need to be designed.  The insert portion would specify &= quot;DEFAULT" for sequence columns and would execute nextval() only if= the ON MISSING portion is executed.

 

Fundamentally, the dif= ference is that ON MISSING is considerably less complicated than ON CONFLIC= T.  What is wanted here is an ON MISSING interpretation but what we've= implemented is ON CONFLICT.  It seems that the hackers are in agreeme= nt that our implementation of ON CONFLICT is consistent with its definition= .  That it doesn't efficiently solve problems better handled by ON MIS= SING - while unfortunate - doesn't constitute a bug: only an opportunity fo= r future enhancement.

=  =

David J.

<= div>

 

<= span style=3D'font-size:12.0pt;font-family:"Arial",sans-serif'> <= /o:p>

=E2=80=8B

<= p class=3DMsoNormal> 

 

 

= --_2E708437-EAD2-47D7-973A-1431FADE94A2_--