通常使用递归公用表表达式来完成此操作。
with recursive cte as ( select descriptor_value_id, parent_value_id, 1 as level from descriptor_value where descriptor_value_id = 87 union all select p.descriptor_value_id, p.parent_value_id, c.level + 1 from descriptor_value p join cte c on c.parent_value_id = p.descriptor_value_id)select * from cte;
connectby()自Postgres 8.4中引入递归CTE以来,该功能几乎已过时



