Databases · Middle · Question 22 of 75
What does INSERT ... ON CONFLICT (email) DO UPDATE do?
- 1Inserts the row and ignores any errors
- 2Updates all rows with the same email
- ✓Correct answer: Inserts the row, or updates the existing row if the unique key already exists (an atomic upsert)
Explanation
It's safe under concurrency, unlike 'select, then insert or update'. DO NOTHING simply skips duplicates. The conflict target needs a unique index.