Skip to content

Commit

Permalink
[#1038] Fix unreliable ordering of upward CTE.
Browse files Browse the repository at this point in the history
  • Loading branch information
David Read committed Jul 30, 2013
1 parent 4db2d24 commit 6d97199
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions ckan/model/group.py
Expand Up @@ -396,17 +396,17 @@ def __repr__(self):
INNER JOIN public.group G ON G.id = child.table_id
WHERE G.type = :type AND G.state='active';"""

HIERARCHY_UPWARDS_CTE = """WITH RECURSIVE parenttree(id) AS (
HIERARCHY_UPWARDS_CTE = """WITH RECURSIVE parenttree(depth) AS (
-- non-recursive term
SELECT M.* FROM public.member AS M
SELECT 0, M.* FROM public.member AS M
WHERE table_id = :id AND M.table_name = 'group' AND M.state = 'active'
UNION
-- recursive term
SELECT M.* FROM public.member M
JOIN parenttree as PG ON PG.group_id = M.table_id
WHERE M.table_name = 'group' AND M.state = 'active'
SELECT PG.depth + 1, M.* FROM parenttree PG, public.member M
WHERE PG.group_id = M.table_id AND M.table_name = 'group' AND M.state = 'active'
)
SELECT G.* FROM parenttree AS PT
SELECT G.*, PT.depth FROM parenttree AS PT
INNER JOIN public.group G ON G.id = PT.group_id
WHERE G.type = :type AND G.state='active';"""
WHERE G.type = :type AND G.state='active'
ORDER BY PT.depth DESC;"""

0 comments on commit 6d97199

Please sign in to comment.