© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•3y ago•
15 replies
Meexa

How to do "onConflictDoUpdate" when inserting an array of values?

I want to add multiple rows to my table but it has a unique key, so it has to update the row if there is a conflict. How do I do this with the ORM?

await db
  .insert(items)
  .values(
    chunk.map((item) => ({
      auctionHouseId: Number(auctionHouseId),
      itemId: item.itemId,
      // ...
    })),
  )
  .onConflictDoUpdate({
    target: [items.itemId, items.auctionHouseId],
    set: {
      // What do I put in here? This is outside of the `map` context
    },
  });
await db
  .insert(items)
  .values(
    chunk.map((item) => ({
      auctionHouseId: Number(auctionHouseId),
      itemId: item.itemId,
      // ...
    })),
  )
  .onConflictDoUpdate({
    target: [items.itemId, items.auctionHouseId],
    set: {
      // What do I put in here? This is outside of the `map` context
    },
  });
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

onConflictDoUpdate array
Drizzle TeamDTDrizzle Team / help
3y ago
Return object instead of an array when inserting object
Drizzle TeamDTDrizzle Team / help
2y ago
Can someone explain how can I use .onConflictDoUpdate with array of values?
Drizzle TeamDTDrizzle Team / help
2y ago
How do default array values work?
Drizzle TeamDTDrizzle Team / help
3y ago