Torbjørn
Torbjørn
Explore posts from servers
DTDrizzle Team
Created by Torbjørn on 9/15/2024 in #help
How do I use the with statement when inserting with select?
How can I get this insert built with drizzle? Insert only has "values", and I am not sure how to construct this in drizzle
WITH "add_favorite_cte" AS (
SELECT
"id" as favorite_list_id,
'my product id' as product_id
FROM
"favorite_lists"
WHERE
"favorite_lists"."user_id" = 'my user id'
)
INSERT INTO favorite_list_item (id, createdAt, favorite_list_id, product_id)
SELECT
(SELECT MAX(id) + 1 FROM favorite_list_item), -- I the $default here preferably
(SELECT (strftime('%Y-%m-%dT%H:%M:%f', 'now') || 'Z')), -- I the $default here preferably
"favorite_list_id",
"product_id"
FROM
"add_favorite_cte"
WITH "add_favorite_cte" AS (
SELECT
"id" as favorite_list_id,
'my product id' as product_id
FROM
"favorite_lists"
WHERE
"favorite_lists"."user_id" = 'my user id'
)
INSERT INTO favorite_list_item (id, createdAt, favorite_list_id, product_id)
SELECT
(SELECT MAX(id) + 1 FROM favorite_list_item), -- I the $default here preferably
(SELECT (strftime('%Y-%m-%dT%H:%M:%f', 'now') || 'Z')), -- I the $default here preferably
"favorite_list_id",
"product_id"
FROM
"add_favorite_cte"
2 replies