Skip to content

Instantly share code, notes, and snippets.

@robertsosinski
Created August 3, 2011 17:40
Show Gist options
  • Save robertsosinski/1123254 to your computer and use it in GitHub Desktop.
Save robertsosinski/1123254 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