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