Last active
December 21, 2015 22:59
-
-
Save charlycoste/6379320 to your computer and use it in GitHub Desktop.
Fetches all fields of all ancestors for the node 267 (works only with 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 ezcontentobject_ancestors(node_id, parent_node_id) AS ( | |
SELECT node_id, parent_node_id | |
FROM ezcontentobject_tree | |
WHERE parent_node_id > 0 | |
UNION | |
SELECT parents.node_id, ancestors.parent_node_id | |
FROM ezcontentobject_tree as parents, ezcontentobject_ancestors as ancestors | |
WHERE parents.parent_node_id = ancestors.node_id | |
), ancestors AS ( | |
SELECT * FROM ezcontentobject_ancestors | |
) | |
SELECT parents.* | |
FROM ezcontentobject_tree as parents, ancestors | |
WHERE parents.node_id = ancestors.parent_node_id and ancestors.node_id = 267 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment