Skip to content

can onConflictDoUpdate coalesce? #1749

Closed Answered by Angelelz
jiangok2006 asked this question in Q&A
Discussion options

You must be logged in to vote

Can you check if this would work?

let row = { id: 1, name: "john", age: null }
await drizzle(db).insert(users).values(row)
        .onConflictDoUpdate(
            {
                target: users.id,
                set: {
                    ...row,
                    age: sql`coalesce(${row.age}, excluded.age)`
                }
            }).returning();

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@shawnmclean
Comment options

Answer selected by jiangok2006
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants