Upsert (On Conflict) in Drizzle ORM

From the Drizzle ORM cheat sheet ยท Insert / Update / Delete ยท verified Jul 2026

Upsert (On Conflict)

Insert or update on conflict using onConflictDoUpdate or onConflictDoNothing.

typescript
// Upsert โ€” update on conflict
await db.insert(users).values({
  email: 'alice@example.com',
  name: 'Alice Updated',
}).onConflictDoUpdate({
  target: users.email,
  set: { name: 'Alice Updated' },
});
๐Ÿ’ก target must be a unique or PK column(s)
โšก sql`excluded.*` references incoming values
๐Ÿ“Œ onConflictDoNothing silently skips duplicates
๐ŸŸข Combine with .returning() to get final row
insertupsertconflict

More Drizzle ORM tasks

Back to the full Drizzle ORM cheat sheet