Slide 19
Slide 19 text
-- Hacker News / Reddit clone, Postgres syntax
WITH RECURSIVE
tree(id, in_reply_to, author_id, content)
AS (
SELECT id, in_reply_to, author_id, content
FROM comments
WHERE id = ?
UNION ALL
SELECT child.id, child.in_reply_to,
child.author_id, child.content
FROM tree parent, comments child
WHERE parent.id = child.in_reply_to
) SELECT * FROM tree;