我正在尝试将此查询转换为 jOOQ,但卡在了“||”上我用它来将值连接到数组。
with recursive nodes(node_key, parent_ids, parent_path) as (
select node_key, array[node_key] as parent_ids, array[name::text] as parent_path
from node
where parent_node_key is null
union all
select c.node_key, parent_ids || c.node_key, parent_path || c.name::text
from node c
join nodes n on n.node_key = c.parent_node_key
)
select * from nodes order by parent_path;
到目前为止我已经完成的jOOQ代码:
dsl.withRecursive( name( "nodes" )
.fields( "node_key",
"parent_ids",
"parent_path" ).as(
select(
NODE.NODE_KEY,
array( NODE.NODE_KEY).as( "parent_ids" ),
array( NODE.NAME).as( "parent_path" )
)
.from( NODE)
.where( NODE.PARENT_NODE_KEY.isNull() )
.unionAll(
select( NODE.NODE_KEY,
field( "parent_ids" ))
) )
) );
如何将值连接到数组?
最佳答案
使用 arrayCat 函数而不是运算符。
关于java - 如何在jOOQ中表示连接运算符(||)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68149549/