【发布时间】:2021-09-09 22:38:28
【问题描述】:
我正在尝试将此查询转换为 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" ))
) )
) );
如何将值连接到数组?
【问题讨论】:
标签: java postgresql jooq