Open stabildev opened 7 months ago
@AndriiSherman should this also include DELETE as well?
WITH deleted AS (DELETE FROM table WHERE condition IS TRUE RETURNING *) SELECT count(*) FROM deleted;
IMO it should include INSERT, SELECT, UPDATE and DELETE as Drizzle aims to be full featured SQL-in-TS
This needs to be added, as it is something that appears in complicated apps! And both MySQL and Postgres support such CTE queries.
+1
In my case, I need to use it with UPDATE. All operations are important for this feature.
Maybe there needs to be a note on the documentation that it only supports SELECT for now.
Please add this!
Is this why I get the error qb.getSelectedFields is not a function
(pg-core/db.js:88:44
) with the following code?
const newTimezoneId = db
.$with("new_timezone_id")
.as(
db
.insert(timezones)
.values({ name: "UTC" })
.onConflictDoNothing()
.returning({ id: timezones.id }),
);
Describe what you want
Drizzle ORM supports
SELECT
queries in CTEs (WITH
clauses). From the docs:Currently, Drizzle does not support
INSERT
queries in CTEs. Example of such a query:As you can see, this would be very useful for nested inserts in a single query and should be supported by Drizzle to be a feature complete SQL query builder.