Re: [GENERAL] Storing a tree - Mailing list pgsql-jdbc

From Antonio Fiol Bonnín
Subject Re: [GENERAL] Storing a tree
Date
Msg-id 3BF228B7.DF1DC0E1@w3ping.com
Whole thread Raw
List pgsql-jdbc
> Maybe you like this: I'm thinking of building a table to represent
> those "nested pods":
>
>    +------A-------+        +------A------+
>     +B++----C----+          +B++----C---+
>         +D++E++F+               +D++-E-+
>                                     +F+
>           |                     |
>           V                     V
>
>    +------A------+         +----A----+
>    +B+ +----C----+         +B+ +--C--+
>     0  +D+ +E+ +F+          0  +D+ +E+
>                             0   0  +F+
>
> So for each node it's important to know, how many cols it spans:
>
>   select count(t2.lft) from p t1, p t2 where t1.lft=123
>   and t2.lft between t1.lft and t1.rgt and t2.rgt=t2.lft+1;

Just a comment for those reading this post: Apart from the phrasing Knut gave
in his post ("how many cols it spans"), his query may be rephrased in English
as the more abstract "Give me the quantity of LEAF nodes (nodes with no other
nodes under them) that lay under (or at) the specified node".

I stated "or at", because you will get a count of 1 if you ask for the
quantity of leaf nodes "under or at" a leaf node itself.

For Knut: I suppose that you are generating an HTML table with that (and use
the value obtained with that query for the COLSPAN option. If so, you are
probably getting your nodes with a more complex request. (order by level,
lft), if probably something that you included in your query. Could you share
with us the complete query (I may be doing something similar in the near
future).

Thank you very much.

Antonio


pgsql-jdbc by date:

Previous
From: Barry Lind
Date:
Subject: Re: [PATCHES] absolute() error with jdbc7.1-1.2
Next
From: tony
Date:
Subject: Re: PostgreSQL->JDBC->Tomcat->Apache resource uses