我正在尝试将此递归查询从 Oracle Sql 移动到 Redshift。为此,我应该能够摆脱下面编写的代码中的“CONNECT BY”、“LEVEL”和“PRIOR”命令。我想在 WITH - UNION ALL 语句中移动递归模式,但我不确定如何管理“LEVEL”函数。有没有人能帮我重写这段代码,去掉“CONNECT BY”、“LEVEL”和“PRIOR”,但保留层次结构?非常感谢您提前。
WITH
LEVEL_COUNTING AS (
SELECT
t.*
,REGEXP_SUBSTR(STR, '[^,]+', 1, LEVEL) AS SINGLE_ELEMENT
,LEVEL AS element_no
FROM
t CONNECT BY INSTR(STR, ',', 1, LEVEL - 1) > 0
AND id = PRIOR id
AND PRIOR DBMS_RANDOM.VALUE IS NOT NULL)