我在彼此之间有2个for循环.对于loop1中的每一行’A’,’B’,’C’,我需要访问分层树以找到loop2中组’X’的所有父项.这使我使用CTE,我需要分别找到每一行的路径.在循环中使用CTE不是确定我可以匹配每个组ID的解决方案.提到这个链接,但不能说出很多
Looping hierarchy CTE
使用flask框架的cron作业的代码片段:
s = select([rt_issues]).\
where(
and_(
rt_issues.c.status !='Closed',
rt_issues.c.assigned_to != None
))
rs = conn.execute(s)
if rs.rowcount > 0:
s4 = text('with recursive rec_grp as(select id, parent_id, name, head, 1 as level, array[id] as path_info from groups union all select grp1.id, grp1.parent_id, grp1.name, grp1.head, rc.level + 1, rc.path_info||grp1.id from groups grp1 join rec_grp rc on grp1.id = rc.parent_id) select distinct id, parent_id, name, head, path_info from rec_grp order by id')
rs4 = conn.execute(s4)
for r in rs:
head_list = []
hierarchical_grps = []