Created
March 3, 2018 17:35
-
-
Save jonpemby/d5c5a5c4b4befaef52f832be1cc9ff70 to your computer and use it in GitHub Desktop.
Recursive comments in PostgreSQL
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 co (id, parent_id, body) as | |
(select c.id, c.parent_id, c.body | |
from comments c | |
where c.id = 1 | |
union all | |
select c.id, c.parent_id, c.body | |
from co | |
join comments c | |
on c.parent_id = co.id) | |
select * from co; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment