insert from select

I am trying to convert a SQL query like this to drizzle:
INSERT INTO table_name (name)
SELECT
name || ' (Copy)',
FROM table_name
WHERE id = 123;
INSERT INTO table_name (name)
SELECT
name || ' (Copy)',
FROM table_name
WHERE id = 123;
but I really don't see how to do it without going for raw SQL. Any pointers?
1 Reply
tcurdt
tcurdtOP2w ago
From the chat:
db
.insert(table)
.select(
db
.select({ name: sql`${table.name} || ' (Copy)'` })
.from(table)
.where(eq(table.id, 123))
);
db
.insert(table)
.select(
db
.select({ name: sql`${table.name} || ' (Copy)'` })
.from(table)
.where(eq(table.id, 123))
);

Did you find this page helpful?