<
div
><
div
>
with
recursive
tree
as
(
div
><
div
select
obj
,
div
><
div
 
 
 
 
sub
,
div
><
div
 
 
 
 
array
[
obj
]
as
all_ancestors
,
div
><
div
 
 
 
 
array
[
knot_name
]
as
ancestor_names
div
><
div
from
bounds
left
join
knots
on
obj
=
knot_id
div
><
div
where
sub
=
1
and
predicate
='
is_parent
'
div
><
div
><
br
>
div
><
div
union
all
div
><
div
><
br
>
div
><
div
select
c
.
obj
,
div
><
div
 
 
 
 
c
.
sub
,
div
><
div
 
 
 
 
p
.
all_ancestors
||
c
.
obj
,
div
><
div
 
 
 
 
p
.
ancestor_names
||
knot_name
div
><
div
from
bounds
c
div
><
div
 
 
join
tree
p
div
><
div
 
 
on
c
.
sub
=
p
.
obj
div
><
div
 
 
and
c
.
obj
<>
ALL
(
p
.
all_ancestors
)
--
avoids
endless
loops
div
><
div
 
 
left
join
knots
on
c
.
obj
=
knot_id
div
><
div
>)
div
><
div
>
select
all_ancestors
,
ancestor_names
div
><
div
>
from
tree
order
by
all_ancestors
;
div
>
div
><
div
><
br
>
div
>