Upsert Multiple using EXCLUDED

hey there - I want to upsert multiple values and overwrite certain fields in case of conflicts. using plain SQL it'd be something like this:
insert into
"surveil" ("id", "last_seen", "name")
values
('1','2023-09-19 10:50:38.285+00', 'BanuniZ'),
('2','2023-09-19 10:50:38.285+00', 'Misha')
on conflict (id) do update set "last_seen" = EXCLUDED."last_seen"
insert into
"surveil" ("id", "last_seen", "name")
values
('1','2023-09-19 10:50:38.285+00', 'BanuniZ'),
('2','2023-09-19 10:50:38.285+00', 'Misha')
on conflict (id) do update set "last_seen" = EXCLUDED."last_seen"
how could I achieve this with drizzle? I couldn't find anything in the docs...
2 Replies
MAST
MAST13mo ago
You can do this on the insert:
.onConflictDoUpdate({ title: sql`excluded.${sql.identifier('last_seen')}` })
.onConflictDoUpdate({ title: sql`excluded.${sql.identifier('last_seen')}` })
So you just write a simple insert and then do a onConflictDoUpdate.
BaNuni
BaNuniOP13mo ago
yeah that's what I'll be doing, but I thought there might me a built-in solution for that
Want results from more Discord servers?
Add your server