Skip to content

Instantly share code, notes, and snippets.

@ambantis
Created October 1, 2013 19:45
Show Gist options
  • Save ambantis/6784006 to your computer and use it in GitHub Desktop.
Save ambantis/6784006 to your computer and use it in GitHub Desktop.
a Postgres view that recursively finds all children, grand-children, great-grand-children, etc. of a Google Drive folder
CREATE VIEW scion_view AS
WITH RECURSIVE scions(id, scion) AS (
SELECT c.id, c.child
FROM children AS c
UNION ALL
SELECT s.id, c.child
FROM children AS c, scions AS s
WHERE c.id = s.scion)
SELECT * FROM scions ORDER BY id, scion;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment