pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Paul <paul@salesintel.com>
To: David G. Johnston <david.g.johnston@gmail.com>
Cc: Andres Freund <andres@anarazel.de>
Cc: Peter Geoghegan <pg@heroku.com>
Cc: pgsql-bugs <pgsql-bugs@postgresql.org>
Subject: Re: BUG #13846: INSERT ON CONFLICTconsumessequencersonconflicts
Date: Fri, 6 May 2016 14:06:18 -0600
Message-ID: <572cf946.489b320a.429be.ffffd369@mx.google.com> (raw)
In-Reply-To: <CAKFQuwb+-KT5UHs+pTn2-TTzs5ZPDG9kwSp2Oo3c1pr9qxfNtQ@mail.gmail.com>
References: <20160105150227.1117.51692@wrigleys.postgresql.org>
	<20160105161326.GD7650@awork2.anarazel.de>
	<CAM3SWZS2jd1Ci2TR2bjBXqZgK3JdoFin9yGbC5TQdYdF12RBuA@mail.gmail.com>
	<CAOwSVr_9FARiegvC54VqZiTz9A3ryuaAbi8XHYha+y=NHmeQpw@mail.gmail.com>
	<20160106181946.GE7650@awork2.anarazel.de>
	<568d8060.291cb60a.e8a06.ffff9d00@mx.google.com>
	<CAM3SWZRQiijB6rRB0vwXyP2JskZ2itNhngFTKNXDYHXJ-Ao8XA@mail.gmail.com>
	<568d8e74.d1a9ca0a.d9558.ffff9026@mx.google.com>
	<20160106221130.GG7650@awork2.anarazel.de>
	<568dadd1.42beca0a.8c605.fffff6eb@mx.google.com>
	<CAKFQuwb+-KT5UHs+pTn2-TTzs5ZPDG9kwSp2Oo3c1pr9qxfNtQ@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

Hi Dave, 
Thanks for the informative reply. We absolutely agree it’s not a bug in implementation, but maybe a bug in conceptualization with regard to usability. 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 don’t quite understand. We stopped using and went back to a manual approach, which also works great because PostgreSQL is just kinda great 😊.

If any related enhancements where to be done, our ‘holy grail’ would be an implementation of the MERGE statement, like this, or this, or this… We can at least ask for it right?? 😉

Thanks for all your guys’ 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 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 were actually going to be inserted. However, you’re now stating that the INSERT ON CONFLICT will execute a BEFORE INSERT trigger even for records that are not inserted?? That doesn’t seem quite logical, and contrary to ‘old fashioned’ upsert logic. Does this also mean that the BEFORE UPDATE trigger is always called as well, or is it never called?

​This seems to boil down to the two possible ways of manually implementing UPSERT:

UPDATE, if not present, INSERT
INSERT, if failing, UPDATE

In the later the before insert trigger fires and influences whether the insert​
 
​fails.  In the former you are already pretty certain the insert will ​succeed because the UPDATE found no records.

We've implemented INSERT, if failing UPDATE.  The insert has to be attempted 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 INSERT" would need to be designed.  The insert portion would specify "DEFAULT" for sequence columns and would execute nextval() only if the ON MISSING portion is executed.

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

David J.


​

Message-ID: <572cf946.489b320a.429be.ffffd369@mx.google.com>
Permalink:  ../572cf946.489b320a.429be.ffffd369@mx.google.com/
Also on:    postgresql.org/message-id/572cf946.489b320a.429be.ffffd369@mx.google.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: paul@salesintel.com, david.g.johnston@gmail.com, andres@anarazel.de, pg@heroku.com
  Subject: Re: BUG #13846: INSERT ON CONFLICTconsumessequencersonconflicts
  In-Reply-To: <572cf946.489b320a.429be.ffffd369@mx.google.com>
  References: <20160105150227.1117.51692@wrigleys.postgresql.org> <20160105161326.GD7650@awork2.anarazel.de> <CAM3SWZS2jd1Ci2TR2bjBXqZgK3JdoFin9yGbC5TQdYdF12RBuA@mail.gmail.com> <CAOwSVr_9FARiegvC54VqZiTz9A3ryuaAbi8XHYha+y=NHmeQpw@mail.gmail.com> <20160106181946.GE7650@awork2.anarazel.de> <568d8060.291cb60a.e8a06.ffff9d00@mx.google.com> <CAM3SWZRQiijB6rRB0vwXyP2JskZ2itNhngFTKNXDYHXJ-Ao8XA@mail.gmail.com> <568d8e74.d1a9ca0a.d9558.ffff9026@mx.google.com> <20160106221130.GG7650@awork2.anarazel.de> <568dadd1.42beca0a.8c605.fffff6eb@mx.google.com> <CAKFQuwb+-KT5UHs+pTn2-TTzs5ZPDG9kwSp2Oo3c1pr9qxfNtQ@mail.gmail.com> <572cf946.489b320a.429be.ffffd369@mx.google.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox