© 2026 Hedgehog Software, LLC

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

Does onConflictDoUpdate work with composite primary keys?

I have a model defined below:

export const userDevices = pgTable(
  'user_devices',
  {
    id: text('id').notNull(),
    userId: uuid('user_id')
      .notNull()
      .references(() => users.id, {
        onDelete: 'cascade',
      }),
      ...
  },
  (table) => ({
    idUserIdPk: primaryKey(table.id, table.userId),
  }),
);
export const userDevices = pgTable(
  'user_devices',
  {
    id: text('id').notNull(),
    userId: uuid('user_id')
      .notNull()
      .references(() => users.id, {
        onDelete: 'cascade',
      }),
      ...
  },
  (table) => ({
    idUserIdPk: primaryKey(table.id, table.userId),
  }),
);


I want to upsert a row into this table but I'm not sure how to set
target
target
to the composite primary key. Is this possible?

return this.drizzleService.db
      .insert(userDevices)
      .values(data)
      .onConflictDoUpdate({
        target: /* What to do here? */,
        set: data,
      });
return this.drizzleService.db
      .insert(userDevices)
      .values(data)
      .onConflictDoUpdate({
        target: /* What to do here? */,
        set: data,
      });
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

Composite primary key, multiple primary keys
Drizzle TeamDTDrizzle Team / help
2y ago
Composite Primary Key from Foreign Keys
Drizzle TeamDTDrizzle Team / help
3y ago
SQLite onConflictDoUpdate does not work as expected on composite primary key or unique constraint
Drizzle TeamDTDrizzle Team / help
2y ago
Switching between single and composite primary keys
Drizzle TeamDTDrizzle Team / help
2y ago