Simple insertOrUpdate (insert ... on duplicate key update)
See original GitHub issueProblem
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:
- Created 2 years ago
- Comments:9 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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 🥰
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!