Re: [GENERAL] Storing a tree

From: Antonio Fiol Bonnín <fiol(at)w3ping(dot)com>
To: knut(dot)suebert(at)web(dot)de, pgsql-jdbc(at)postgresql(dot)org
Subject: Re: [GENERAL] Storing a tree
Date: 2001-11-14 08:17:59
Message-ID: 3BF228B7.DF1DC0E1@w3ping.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general 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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message tony 2001-11-14 09:06:51 Re: lower does not handle german umlaut
Previous Message David Ford 2001-11-14 07:34:51 UPDATE w/ subselect doing locking

Browse pgsql-jdbc by date

  From Date Subject
Next Message Nikk Anderson 2001-11-14 08:20:19 Re: PostgreSQL->JDBC->Tomcat->Apache resource uses
Previous Message Barry Lind 2001-11-14 04:11:47 Re: [PATCHES] absolute() error with jdbc7.1-1.2