Matt
Matt
Explore posts from servers
DTDrizzle Team
Created by Matt on 3/27/2024 in #help
Upsert Multiple Rows with Conflicts postgres
Is there a way to upsert multiple rows when there could be conflicts on some of the rows? I have this code I tried below but spreading out the userValues in the set doesn't work of course, the usersValue is an array of users that could contain information about new users or existing users with new information. Is there a way to do it all in this one command or do I need to break it down before attempting the db insert?
await db
.insert(users)
.values(userValues)
.onConflictDoUpdate({
target: users.UserId,
set: {
...userValues,
updatedAt: new Date(),
},
});
await db
.insert(users)
.values(userValues)
.onConflictDoUpdate({
target: users.UserId,
set: {
...userValues,
updatedAt: new Date(),
},
});
13 replies