`with` with insert

How can I get withto work with insert...returning? The docs mention the with clause only for select
No description
4 Replies
Lloyd
Lloyd5mo ago
Hey, did you find a solution to this @henrik? It looks like it's just not supported yet, which is a shame
henrik
henrik5mo ago
Nope, talked to @Andrew Sherman on twitter but no response yet. Might even only be a type issue fwiw The pattern is really useful for optimization as it eliminates the need to have an additional query
henrik
henrik5mo ago
@Lloyd I created an issue on GH. Might help to upvote it https://github.com/drizzle-team/drizzle-orm/issues/2078
GitHub
[FEATURE]: allow INSERT in CTEs (WITH clauses) · Issue #2078 · driz...
Describe what you want Drizzle ORM supports SELECT queries in CTEs (WITH clauses). From the docs: const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42))); const result...
Lloyd
Lloyd5mo ago
I've given it an upvote - thanks Yeah it's great - we use this pattern a lot, we also use .$with.select and then .with().insert(), which they do support already, just not the other way around. Looks like they'll get round to it though.