© 2026 Hedgehog Software, LLC

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

upsert with excluded using column name

I'm trying to do a an upsert like so
await db.insert(user).values(values).onConflictDoUpdate({
  target: user.id,
  set: {
    // Defined in schema as full_name
    fullName: sql`EXCLUDED.${user.fullName.name}`
}
})
await db.insert(user).values(values).onConflictDoUpdate({
  target: user.id,
  set: {
    // Defined in schema as full_name
    fullName: sql`EXCLUDED.${user.fullName.name}`
}
})

When I try to do this, I'm getting error
PostgresError: syntax error at or near "$265"
PostgresError: syntax error at or near "$265"
. If I do
fullName: sql`EXCLUDED.full_name` 
fullName: sql`EXCLUDED.full_name` 
, it works. But I would like to do so using the
.name
.name
property as it will be easier to catch if there's an issue. How do I do it?
Solution
Hello @vr7bd. You can follow this guide to do upsert
https://orm.drizzle.team/learn/guides/upsert

In your case should be

await db.insert(user).values(values).onConflictDoUpdate({
  target: user.id,
  set: {
    // Defined in schema as full_name
    fullName: sql.raw(`excluded.${user.fullName.name}`)
}
})
await db.insert(user).values(values).onConflictDoUpdate({
  target: user.id,
  set: {
    // Defined in schema as full_name
    fullName: sql.raw(`excluded.${user.fullName.name}`)
}
})
Drizzle ORM - Upsert Query
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
Jump to solution
Drizzle TeamJoin
The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!
11,879Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Upsert Multiple using EXCLUDED
Drizzle TeamDTDrizzle Team / help
3y ago
onConflictDoUpdate excluded with a dynamic column
Drizzle TeamDTDrizzle Team / help
2y ago
Upsert with multi-column unique index?
Drizzle TeamDTDrizzle Team / help
3y ago
Issue with truncating column names using `with`
Drizzle TeamDTDrizzle Team / help
2y ago