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