【问题标题】:Does Presto SQL support recursive query using CTE just like SQL Server? e.g. employee hierarchy levelPresto SQL 是否像 SQL Server 一样支持使用 CTE 进行递归查询?例如员工等级
【发布时间】:2019-08-21 00:54:10
【问题描述】:

我想在 Presto 中使用 CTE 编写一个递归查询来查找 Employee Hierarchy。 Presto 支持递归查询吗? 当我把简单的递归写成

with cte as(select 1 n union all select cte.n+1 from cte where n<50) select * from cte

它给出的错误是

运行查询时出错:第 3:32 行:表 cte 不存在

【问题讨论】:

    标签: presto trino


    【解决方案1】:

    当前答案

    Trino 支持递归查询,但 Presto 的not PrestoDB 实现。

    旧答案

    Presto 语法支持WITH RECURSIVE name AS ...,但支持recursive WITH queries are not implemented

    这将作为功能请求进行跟踪: https://github.com/trinodb/trino/issues/1122

    【讨论】:

      【解决方案2】:
      WITH RECURSIVE cte(n) AS (
          SELECT 1
          UNION ALL
          SELECT n + 1 FROM cte WHERE n < 50)
      SELECT * from cte
      

      错误:Recursion depth limit exceeded (10)

      调整max_recursion_depth

      【讨论】:

        猜你喜欢
        • 2010-11-03
        • 1970-01-01
        • 2016-01-25
        • 2012-12-25
        • 1970-01-01
        • 2011-09-25
        • 2010-09-08
        • 1970-01-01
        • 2021-10-10
        相关资源
        最近更新 更多