Snowflake,递归 CTE,获取错误字符串 'AAAA_50>BBBB_47>CCCC_92' 太长,将在 'CONCAT' 中被截断
Snowflake, Recursive CTE , Getting error String 'AAAA_50>BBBB_47>CCCC_92' is too long and would be truncated in 'CONCAT'
我正在雪花中创建递归 CTE 以获得完整路径并出现以下错误:
字符串 'AAAA_50>BBBB_47>CCCC_92' 太长,将在 'CONCAT'
中被截断
我的脚本如下:(它在 2 级时工作正常,在 3 级时开始失败)
with recursive plant
(child_col,parent_col,val )
as
(
select child_col, '' parent_col , trim(child_col) from My_view
where condition1 = 'AAA'
union all
select A.child_col,A.parent_col,
concat(trim(A.child_col),'>')||trim(val)
from My_view A
JOIN plant as B ON trim(B.child_col) = trim(A.parent_col)
)
select distinct * from plant
很可能 child_col 数据类型定义为 VARCHAR (N),此类型正在传递。因为 CONCAT Returns:
The data type of the returned value is the same as the data type of
the input value(s).
尝试像这样 cast(trim(child_col) as string)
:
将类型显式转换为 string
完整代码:
with recursive plant (child_col,parent_col,val )
as (
select child_col, '' parent_col , cast(trim(child_col) as string)
from My_view
where condition1 = 'AAA'
union all
select A.child_col, A.parent_col, concat(trim(A.child_col),'>')||trim(val)
from My_view A
join plant as B ON trim(B.child_col) = trim(A.parent_col)
)
select distinct * from plant
请记住,Snowflake 中的递归默认限制为 100 次循环。
如果你想增加它们,你需要联系支持。
我正在雪花中创建递归 CTE 以获得完整路径并出现以下错误:
字符串 'AAAA_50>BBBB_47>CCCC_92' 太长,将在 'CONCAT'
中被截断我的脚本如下:(它在 2 级时工作正常,在 3 级时开始失败)
with recursive plant
(child_col,parent_col,val )
as
(
select child_col, '' parent_col , trim(child_col) from My_view
where condition1 = 'AAA'
union all
select A.child_col,A.parent_col,
concat(trim(A.child_col),'>')||trim(val)
from My_view A
JOIN plant as B ON trim(B.child_col) = trim(A.parent_col)
)
select distinct * from plant
很可能 child_col 数据类型定义为 VARCHAR (N),此类型正在传递。因为 CONCAT Returns:
The data type of the returned value is the same as the data type of the input value(s).
尝试像这样 cast(trim(child_col) as string)
:
完整代码:
with recursive plant (child_col,parent_col,val )
as (
select child_col, '' parent_col , cast(trim(child_col) as string)
from My_view
where condition1 = 'AAA'
union all
select A.child_col, A.parent_col, concat(trim(A.child_col),'>')||trim(val)
from My_view A
join plant as B ON trim(B.child_col) = trim(A.parent_col)
)
select distinct * from plant
请记住,Snowflake 中的递归默认限制为 100 次循环。 如果你想增加它们,你需要联系支持。