© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•3y ago•
4 replies
myles

WITH RECURSIVE support… or suggestions for how to approach?

Hi. I'm absolutely loving Drizzle after a little while in both Prisma and TypeORM and 15 years of Rails + ActiveRecord.

I have the following query that uses WITH RECURSIVE. I'd love to use Drizzle's query builder but I cant see how I might tackle that. Am I right in thinking that this is going to need to be supported in the
select
select
helper https://orm.drizzle.team/docs/select#with-clause ?


```
WITH RECURSIVE layer AS (
SELECT
id,
name,
parent_id,
0 AS level
FROM
risks
WHERE
parent_id IS NULL
UNION ALL
SELECT
child.id,
child.name,
child.parent_id,
level + 1 AS level
FROM
risks child
JOIN layer l ON l.id = child.parent_id
)
SELECT
l.*,
parent.id AS parent_id
FROM
layer l
LEFT JOIN risks parent ON l.parent_id = parent.id
ORDER BY
level;
SQL Select - Drizzle ORM
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
Drizzle TeamJoin
The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!
11,879Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

WITH RECURSIVE
Drizzle TeamDTDrizzle Team / help
3y ago
Invalid types with recursive relations
Drizzle TeamDTDrizzle Team / help
2w ago
Looking for suggestions
Drizzle TeamDTDrizzle Team / help
2y ago
Recursive CTEs
Drizzle TeamDTDrizzle Team / help
2y ago