© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•2y ago•
4 replies
Icemourne

Can someone explain how can I use .onConflictDoUpdate with array of values?

If where is conflict somewhere with some value in array how can I use values from that array as new value?
In documentation it shows how to handle that then setting one value but not array of values
// for single value
await db.insert(users)
  .values({ id: 1, name: 'Dan' })
  .onConflictDoUpdate({ target: users.id, set: { name: 'John' } });
// for single value
await db.insert(users)
  .values({ id: 1, name: 'Dan' })
  .onConflictDoUpdate({ target: users.id, set: { name: 'John' } });

but how about this
await db.insert(users)
  .values([{ id: 1, name: 'Dan' }, { id: 2, name: 'Tom' }, { id: 3, name: 'Martin' }])
  .onConflictDoUpdate({ target: users.id, set: ??? }); // if where was conflict on id 2 how can I set new name using values in array
await db.insert(users)
  .values([{ id: 1, name: 'Dan' }, { id: 2, name: 'Tom' }, { id: 3, name: 'Martin' }])
  .onConflictDoUpdate({ target: users.id, set: ??? }); // if where was conflict on id 2 how can I set new name using values in array
Drizzle TeamJoin
The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!
11,879Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

How to do "onConflictDoUpdate" when inserting an array of values?
Drizzle TeamDTDrizzle Team / help
3y ago
onConflictDoUpdate array
Drizzle TeamDTDrizzle Team / help
3y ago
How to use "onConflictDoUpdate" with composite key?
Drizzle TeamDTDrizzle Team / help
3y ago
"onConflictDoUpdate" fails with error in Array.flatMap
Drizzle TeamDTDrizzle Team / help
2y ago