Created
November 18, 2013 10:10
-
-
Save zeroDivisible/7525530 to your computer and use it in GitHub Desktop.
This is just an example pgSQL query. I don't have the exact schema right now, but basically, there was a tag (stored in table tags) which was mapping to parent (using parent_id) tag from the same table. Give a :startingTagId, this query returns a tag and all parents.
This file contains hidden or 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 all_tags(rownum, id) as ( | |
select 1::bigint, id, parent_id from tags where id = :startingTagId | |
union all | |
select rownum + 1, c.id, c.parent_id | |
from all_tags a | |
inner join tags c on a.parent_id = c.id) | |
select * from all_tags |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment