© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•5w ago
koksikSKKJ

onConflictDoUpdate

drizzle orm
Hi.

I have that schema:

export const groupDay = pgTable(
  "groupDay",
  {
    id: uuid().defaultRandom().primaryKey().unique().notNull(),
    name: varchar({ length: 256 }).notNull(),
    isSelected: boolean().default(false),
    isArchavized: boolean().default(false).notNull(),
    userId: uuid()
      .references(() => user.id, { onDelete: "cascade" })
      .notNull(),
  },
  (thisTable) => {
    return [uniqueIndex("groupDayNameUserIdUniqueIndex").on(lower(thisTable.name), thisTable.userId)];
  }
);
export const groupDay = pgTable(
  "groupDay",
  {
    id: uuid().defaultRandom().primaryKey().unique().notNull(),
    name: varchar({ length: 256 }).notNull(),
    isSelected: boolean().default(false),
    isArchavized: boolean().default(false).notNull(),
    userId: uuid()
      .references(() => user.id, { onDelete: "cascade" })
      .notNull(),
  },
  (thisTable) => {
    return [uniqueIndex("groupDayNameUserIdUniqueIndex").on(lower(thisTable.name), thisTable.userId)];
  }
);


and that update:

const drizzleResponse = await drizzleClient
  .insert(groupDay)
  .values({
    name: name,
    userId: userSession.id,
  })
  .returning({
    id: groupDay.id,
  })
  .onConflictDoUpdate({
    target: [groupDay.name, groupDay.userId],
    targetWhere: and(eq(sql`lower(${groupDay.name})`, name.toLowerCase()), eq(groupDay.userId, userSession.id)),
    set: {
      name: name,
      isArchavized: false,
    },
  });
const drizzleResponse = await drizzleClient
  .insert(groupDay)
  .values({
    name: name,
    userId: userSession.id,
  })
  .returning({
    id: groupDay.id,
  })
  .onConflictDoUpdate({
    target: [groupDay.name, groupDay.userId],
    targetWhere: and(eq(sql`lower(${groupDay.name})`, name.toLowerCase()), eq(groupDay.userId, userSession.id)),
    set: {
      name: name,
      isArchavized: false,
    },
  });


The problem is the onConflcitDoUpdate does not work with uniqueIndex with sql lower. Any solution please?
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

Multiple `onConflictDoUpdate()`
Drizzle TeamDTDrizzle Team / help
2y ago
onConflictDoUpdate array
Drizzle TeamDTDrizzle Team / help
3y ago
onConflictDoUpdate() ID entry
Drizzle TeamDTDrizzle Team / help
3y ago
insert multiple rows - onConflictDoUpdate
Drizzle TeamDTDrizzle Team / help
2y ago