I have the following set of data using the postgres ltree plugin to model a tree data structure:
This query allows me to cut the tree returning nodes below the cut:
with data(path) as (SELECT * FROM test WHERE yaxis >= 2 ORDER BY yaxis) select * from data d1 where not exists (select 1 from data d2 where d1.path <> d2.path and d1.path @> d2.path);
Notice, one of the nodes is not a leaf, I would like to take the results from above, and get the leaves and return the aggregated set of data. This is the second query I would like to use:
SELECT * FROM test WHERE path <@ 'Top.Collections.Pictures.Astronomy' and leaf = true;
Notice the 'Top.Collections.Pictures.Astronomy' above, is input from the first query.
This second query returns this set:
The combined result I would like to see, is replacing 'Top.Collections.Pictures.Astronomy' with its children from the second query