noob help: INSERT with JOIN SQL to Drizzle

Frontend developer dabbling with SQL for the first time in years. With the help of ChatGPT I have the following query which works as intended. How do I construct with Drizzle such that I can supply my values using the .values() method?
INSERT INTO billing (team_id, credit_change, credits, type)
SELECT teams.id, billing.credit_change, teams.credits + billing.credit_change, 'runtime'
FROM teams
JOIN (
VALUES
(1, 100),
(2, 200),
(3, 150)
) AS billing(team_id, credit_change)
ON teams.id = billing.team_id;
INSERT INTO billing (team_id, credit_change, credits, type)
SELECT teams.id, billing.credit_change, teams.credits + billing.credit_change, 'runtime'
FROM teams
JOIN (
VALUES
(1, 100),
(2, 200),
(3, 150)
) AS billing(team_id, credit_change)
ON teams.id = billing.team_id;
4 Replies
Luca
LucaOP2y ago
Thanks, what's a temporary workaround that I can employ in the meantime? Is it possible to use the sql`` operator somehow?
Andrii Sherman
yes you can use it
DivMode
DivMode16mo ago
Looking to do something similiar, were you able to get it working @Luca?
Want results from more Discord servers?
Add your server