PostgreSQL中的CTE尾递归吗?

时间:2015-05-04 14:57:41

标签: postgresql recursion common-table-expression

我想知道postgresql中的递归查询,例如下面的查询是否是尾递归的?

WITH RECURSIVE category_tree(id, name, path) AS (
  SELECT id, name, ARRAY[id]
  FROM categories
  WHERE parent_id IS NULL
  UNION ALL
  SELECT categories.id, categories.name, path || categories.id
  FROM category_tree
  JOIN categories ON categories.parent_id=category_tree.id
  WHERE NOT categories.id = ANY(path)
)
SELECT * 
FROM category_tree 
ORDER BY path;

0 个答案:

没有答案