question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is there a way to do upserts in PostgreSQL

See original GitHub issue

I’m relying on using INSERT ... ON CONFLICT (internal_id) DO NOTHING or ``INSERT … ON CONFLICT (internal_id) DO UPDATE …` operations. Especially those updates are tedious to write for wider tables (each property name repeated like 5 times…). Is there a way this library could help me?

If the answer is no, but you’d like to have this functionality, I’d be happy to implement that.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
exyicommented, Jun 23, 2021

MERGE in sql server has issues …… https://sqlperformance.com/2020/09/locking/upsert-anti-pattern

I’d rather say that SQL server is an antipattern… His amazing solution is not that great, since it will only work properly in SERIALIZABLE mode which will lead to even more problems on this joke DBMS (otherwise you might get conflict. The whole point of doing upserts is to get rid of them).

If we have to support Microsoft SQL, I’m definitely not going to implement it. I’ll close this issue, as it does not seem as easy to solve given the constants. Probably best to rely on custom helper functions for a specific use case…

0reactions
davidglassborowcommented, Jun 22, 2021

Out of my depth here but just chiming in to say that to my knowledge MSSQL uses the MERGE statement/syntax for upserts. Possible i misunderstand the conversation though.

Looking here because i’m actually attempting to use the library now for such a situation and it’d help to have.

MERGE in sql server has issues …… https://sqlperformance.com/2020/09/locking/upsert-anti-pattern

Read more comments on GitHub >

github_iconTop Results From Across the Web

UPSERT Operation in PostgreSQL
In PostgreSQL, the UPSERT operation means either UPDATE or INSERT operation. The UPSERT operation allows us to either insert a row or skip...
Read more >
PostgreSQL Upsert Using INSERT ON CONFLICT statement
This tutorial shows you how to use the PostgreSQL upsert feature to insert or update data if the row that is being inserted...
Read more >
PostgreSQL - Upsert
The UPSERT statement is a DBMS feature that allows a DML statement's author to either insert a row or if the row already...
Read more >
UPSERT - PostgreSQL wiki
"UPSERT" is a DBMS feature that allows a DML statement's author to atomically either insert a row, or on the basis of the...
Read more >
PostgreSQL — How to UPSERT safely, easily and fast
DELETE INTO another table · UPDATE INTO another table · Insert, delete and update in ONE statement · UPDATE SELECT a batch of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found