0

I have the following set of data using the postgres ltree plugin to model a tree data structure:

enter image description here

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);

enter image description here

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:

enter image description here

The combined result I would like to see, is replacing 'Top.Collections.Pictures.Astronomy' with its children from the second query

JZ.
  • 21,147
  • 32
  • 115
  • 192
  • http://meta.stackoverflow.com/questions/285551/why-may-i-not-upload-images-of-code-on-so-when-asking-a-question/285557#285557 –  Oct 04 '16 at 18:35
  • I guess I've been using stackoverflow wrong for 7 years. – JZ. Oct 04 '16 at 18:40

0 Answers0