Skip to content

Instantly share code, notes, and snippets.

@mirzap
Forked from robertsosinski/gist:1123254
Created September 30, 2021 15:57
Show Gist options
  • Save mirzap/a12ff04472d49e2aa45d965a727e93d6 to your computer and use it in GitHub Desktop.
Save mirzap/a12ff04472d49e2aa45d965a727e93d6 to your computer and use it in GitHub Desktop.
Recursive breadcrumb query for Postgres
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