Skip to content

Commit

Permalink
Add remark about upsert’s race conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
dtinth committed Oct 18, 2022
1 parent 4a4ea79 commit fdc4451
Showing 1 changed file with 1 addition and 0 deletions.
Expand Up @@ -954,6 +954,7 @@ const user = await prisma.user.update({
#### Remarks
- To perform arithmetic operations on update (add, subtract, multiply, divide), use [atomic updates](#atomic-number-operations) to prevent race conditions.
- Prisma performs the upsert first executing a `SELECT` query to check if the record exists, followed by an `INSERT` or `UPDATE` query depending on the result of the `SELECT` query. Since it does not use the `ON CONFLICT` or the `ON DUPLICATE KEY` clause, [two simultaneous upserts on the same record can result in a “Unique constraint failed” error](https://github.com/prisma/prisma/issues/3242). It is your application’s responsibility to handle the [P2002](error-reference#p2002) error and retry the upsert.
#### Reference
Expand Down

0 comments on commit fdc4451

Please sign in to comment.