-
-
Save mirzap/a12ff04472d49e2aa45d965a727e93d6 to your computer and use it in GitHub Desktop.
Recursive breadcrumb query for Postgres
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with recursive breadcrumbs(id, parent_id, name) as ( | |
select id, parent_id, name | |
from pages | |
where id = 4 | |
union | |
select p.id, p.parent_id, p.name | |
from pages p | |
inner join breadcrumbs b on p.id = b.parent_id | |
) | |
select * from breadcrumbs; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment