Insert multiple rows + onConflictDoUpdate

Is it possible to insert multiple rows (array) and at the same time using the onConflictDoUpdate? I'm trying it out but I get this error:
TypeError: Cannot read properties of undefined (reading 'name')
at ghh5w224esf.js:70758:77
at Array.flatMap (<anonymous>)
at SQLiteAsyncDialect.buildUpdateSet (ghh5w224esf.js:70757:36)
at SQLiteInsert.onConflictDoUpdate (ghh5w224esf.js:70637:186)
at D1_DB.pushCourse (ghh5w224esf.js:79896:65)
at OrgCourseService.insertCoursesFromNtnIntoD1 (ghh5w224esf.js:79874:36)
at async action2 (ghh5w224esf.js:58503:35)
at async callRouteActionRR (ghh5w224esf.js:3315:16)
at async callLoaderOrAction (ghh5w224esf.js:2436:16)
at async submit2 (ghh5w224esf.js:2080:25) {
stack: TypeError: Cannot read properties of undefined (re…16)
at async submit2 (ghh5w224esf.js:2080:25),
message: Cannot read properties of undefined (reading 'name')
}
TypeError: Cannot read properties of undefined (reading 'name')
at ghh5w224esf.js:70758:77
at Array.flatMap (<anonymous>)
at SQLiteAsyncDialect.buildUpdateSet (ghh5w224esf.js:70757:36)
at SQLiteInsert.onConflictDoUpdate (ghh5w224esf.js:70637:186)
at D1_DB.pushCourse (ghh5w224esf.js:79896:65)
at OrgCourseService.insertCoursesFromNtnIntoD1 (ghh5w224esf.js:79874:36)
at async action2 (ghh5w224esf.js:58503:35)
at async callRouteActionRR (ghh5w224esf.js:3315:16)
at async callLoaderOrAction (ghh5w224esf.js:2436:16)
at async submit2 (ghh5w224esf.js:2080:25) {
stack: TypeError: Cannot read properties of undefined (re…16)
at async submit2 (ghh5w224esf.js:2080:25),
message: Cannot read properties of undefined (reading 'name')
}
3 Replies
Dan
Dan17mo ago
Yes, I'm using it like this:
const result = await ctx.db
.insert(Regions)
.values(regionValues)
.onConflictDoUpdate({
target: Regions.id,
set: {
name: sql`EXCLUDED.name`,
en: sql`EXCLUDED.en`,
de: sql`EXCLUDED.de`,
parentId,
},
})
.returning();
const result = await ctx.db
.insert(Regions)
.values(regionValues)
.onConflictDoUpdate({
target: Regions.id,
set: {
name: sql`EXCLUDED.name`,
en: sql`EXCLUDED.en`,
de: sql`EXCLUDED.de`,
parentId,
},
})
.returning();
rodrigo
rodrigoOP17mo ago
Thanks, I've seen this thread where it allows to programatically applied the 'excluded' to all fields! https://github.com/drizzle-team/drizzle-orm/issues/675
GitHub
[BUG]: onConflictDoUpdate error in casing · Issue #675 · drizzle-te...
What version of drizzle-orm are you using? 0.26.3 What version of drizzle-kit are you using? 0.18.1 Describe the Bug Hey all! I've found a funny problem while using drizzle + postgres (Vercel p...
rodrigo
rodrigoOP17mo ago
set: {
...Object.fromEntries(
Object.keys(form.data.processings[0] ?? {}).map(x => [x, sql.raw(`excluded."${x}"`)])
),
// optionally override specific values
// ...
},
set: {
...Object.fromEntries(
Object.keys(form.data.processings[0] ?? {}).map(x => [x, sql.raw(`excluded."${x}"`)])
),
// optionally override specific values
// ...
},
Want results from more Discord servers?
Add your server