PostgreSQL 9.5 Does UPSERT Right (thenewstack.io)
joabj writes: For years, PostgreSQL users would ask when their favorite open source database system would get the UPSERT operator, which can either insert an entry or update it if a previous version already existed. Other RDMS have long offered this feature. Bruce Momjian, one of the chief contributors to PostgreSQL, admits to being embarrassed that it wasn't supported. Well, PostgreSQL 9.5, now generally available, finally offers a version of UPSERT and users may be glad the dev team took their time with it. Implementations of UPSERT on other database systems were "handled very badly," sometimes leading to unexpected error messages Momjian said. Turns out it is very difficult to implement on multi-user systems. "What is nice about our implementation is that it never generates an unexpected error. You can have multiple people doing this, and there is very little performance impact," Momjian said. Because it can work on multiple tables at once, it can even be used to merge one table into another.
Finally. That's all.
Nice.
It has been out for a week, kinda early to pat yourself on the back
Oh. How disappointing. I'll let the team know to remove the code that does this then seeing as you already have a solution.
upserted, this morning.
Religous speak to God. Insane are spoken to by God. When all shut up, one can finally hear Shostakovich in peace
âoeOther RDMS have long offered this feature. Bruce Momjian, one of the chief contributors to PostgreSQL, admits to being embarrassed that it wasn't supported.â
It was even in the summary, let alone the article. No pleasing some people I guess.
Sounds too much like "Up Skirt". Somebody's gonna sue.
Table-ized A.I.
This is great. I've been using PosgreSQL for a while now. It's one of those pieces of software that just does what it's told and doesn't let you down. While I'm saying this there are credible rumours to the effect that the Oracle merge operation is broken. Read the comments to the most upvoted answer at this stack exchange question. The final comment is: :( – Randy Magruder Aug 27 '15 at 16:05
Not reliably. I ended up with retry loops in the client code.
This makes me think that Bruce Momijan may have been thinking about Oracle's implementation of merge when he said that other implementations were handled very badly.
What would be the equivalent long-hand in "traditional" SQL?
Table-ized A.I.
I hope that you're doing the check then insert inside a transaction.
I am TheRaven on Soylent News
That sounds like the "save with replace" bug on the Commodore 1541 disk drive 35 years ago. Plus ca change, eh?
What if two (or more) transactions, need to update, delete, insert the same?
I love race conditions.
Best solution I have is to return failure, and rollback, and ask the user (or calling system), to try again. Trying to solve the race condition often leads to worse situations than just returning a failure.
Oracle has included the 'merge' command for several iterations now, which does the same thing. It is a rich command - those interested can check the documentation at https://docs.oracle.com/database/121/SQLRF/statements_9016.htm#SQLRF01606
this.
try to solve a complex one in code without user interaction and having a deadlock is only the good part.
Moderating "-1, Disagree" is simple censorship. Have the guts to post your opinion. -- Spazmania (174582)
Holy shit was hoping you were trolling. RIP.
fuck
That's how to do it. It has to be managed in a loop transaction side or in the application. This loop is remarkably difficult to get right by most programmers. For example, if a trigger is added to the inserted table after the fact causing an error in some other table, most loop based upsert code I've seen will fail into an infinite loop.
Actually David Bowie was known for leveraging technology in his musical career. Here is the first article that pops up on Google.
Guns don't kill people; Physics kills people! - John Lithgow as Dick Solomon on Third Rock From The Sun
What's broken with the transaction isolation model? The only thing I see is that they don't do the non-transaction "read uncommitted" transaction that lets you see records that other transactions have not committed.
If I have been able to see further than others, it is because I bought a pair of binoculars.