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.

Simple insertOrUpdate (insert ... on duplicate key update)

See original GitHub issue

Problem

I want to create an ez “insert … on duplicate key update” query. I see no reason why this should only be possible via a raw query.

prisma.myTable.insertOrUpdate({data: {a: 1, b: 2, c: 3}, overwrite: {a: true, c: true}})

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

6reactions
windowsdeveloperwannabecommented, Oct 8, 2021

Isn’t upsert, that @pantharshit00 linked to, doing exactly that? What is the difference you are hoping to see here?

The current upsert offered by Prisma has a race condition (#3242). It would be optimal if at least the Postgres/Mysql/Mongodb drivers used the database’s native upsert to avoid that.

I currently have to use raw SQL to do upserts to continue using Prisma. But other than that it’s such a nice library 🥰

0reactions
leafysharkcommented, Nov 1, 2022

Actually I managed to achieve what I was looking for using create/update in nested writes within a for… of loop.

I will take a look into PostGreSQL’s ON CONFLICT. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

13.2.7.2 INSERT ... ON DUPLICATE KEY UPDATE Statement
If you specify an ON DUPLICATE KEY UPDATE clause and a row to be inserted would cause a duplicate value in a UNIQUE...
Read more >
MySQL INSERT ON DUPLICATE KEY UPDATE
The INSERT ON DUPLICATE KEY UPDATE is a MySQL's extension to the SQL standard's INSERT statement. When you insert a new row into...
Read more >
On Duplicate Key Update same as insert - mysql
The UPDATE statement is given so that older fields can be updated to new value. If your older values are the same as...
Read more >
INSERT ON DUPLICATE KEY UPDATE - MariaDB
ON DUPLICATE KEY UPDATE is a MariaDB/MySQL extension to the INSERT statement that, if it finds a duplicate unique or primary key, will...
Read more >
ON DUPLICATE KEY UPDATE to upsert and modify data in ...
The `INSERT...ON DUPLICATE KEY UPDATE` clause lets you handle scenarios where a record should be modified if it exists and added if it...
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