© 2026 Hedgehog Software, LLC

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

Multiple `onConflictDoUpdate()`

Is there a cleaner way to do this? I tried
case
case
and
where
where
in the
sql
sql
statements in one vs chaining, but that didn't work

const stmt = db.insert(characters).values(chars)
    .onConflictDoUpdate({
        target: characters.id,
        set: {
            name: sql`excluded.name`,
            updatedAt: sql`CURRENT_TIMESTAMP`
        },
        where: sql`excluded.name is not null`
    })
    .onConflictDoUpdate({
        target: characters.id,
        set: {
            level: sql`excluded.level`,
            updatedAt: sql`CURRENT_TIMESTAMP`
        },
        where: sql`excluded.level is not null`
    })
    .onConflictDoUpdate({
        target: characters.id,
        set: {
            factionId: sql`excluded.faction_id`,
            updatedAt: sql`CURRENT_TIMESTAMP`
        },
        where: sql`excluded.faction_id is not null`
    })
    .onConflictDoUpdate({
        target: characters.id,
        set: {
            foreground: sql`excluded.foreground`,
            updatedAt: sql`CURRENT_TIMESTAMP`
        },
        where: sql`excluded.foreground is not null`
    })
    .onConflictDoUpdate({
        target: characters.id,
        set: {
            background: sql`excluded.background`,
            updatedAt: sql`CURRENT_TIMESTAMP`
        },
        where: sql`excluded.background is not null`
    })
const stmt = db.insert(characters).values(chars)
    .onConflictDoUpdate({
        target: characters.id,
        set: {
            name: sql`excluded.name`,
            updatedAt: sql`CURRENT_TIMESTAMP`
        },
        where: sql`excluded.name is not null`
    })
    .onConflictDoUpdate({
        target: characters.id,
        set: {
            level: sql`excluded.level`,
            updatedAt: sql`CURRENT_TIMESTAMP`
        },
        where: sql`excluded.level is not null`
    })
    .onConflictDoUpdate({
        target: characters.id,
        set: {
            factionId: sql`excluded.faction_id`,
            updatedAt: sql`CURRENT_TIMESTAMP`
        },
        where: sql`excluded.faction_id is not null`
    })
    .onConflictDoUpdate({
        target: characters.id,
        set: {
            foreground: sql`excluded.foreground`,
            updatedAt: sql`CURRENT_TIMESTAMP`
        },
        where: sql`excluded.foreground is not null`
    })
    .onConflictDoUpdate({
        target: characters.id,
        set: {
            background: sql`excluded.background`,
            updatedAt: sql`CURRENT_TIMESTAMP`
        },
        where: sql`excluded.background is not null`
    })
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

insert multiple rows - onConflictDoUpdate
Drizzle TeamDTDrizzle Team / help
2y ago
Multiple onConflictDoUpdate's supported?
Drizzle TeamDTDrizzle Team / help
2y ago
Insert multiple rows + onConflictDoUpdate
Drizzle TeamDTDrizzle Team / help
3y ago
onConflictDoUpdate
Drizzle TeamDTDrizzle Team / help
5w ago