hierarchy select question? - Mailing list pgsql-general

From
Subject hierarchy select question?
Date
Msg-id 965070940.3985d05c78eb5@mail.gurubase.com
Whole thread Raw
List pgsql-general
Dear all,

I would like to define threads in message system for replies to message but if
I define too many level, I am afraid I have problem in the select...

Say, I have define 3 levels:

    1
   / \
  2   3
 /\    \
4   5   6

It means message 2 is a reply to 1.
                 4 is a further follow-up of 2...etc

In table format, I would present it with

Table A
ParentId  ChildId
1         2
1         3
2         4
2         5
3         6

I think I can issue the command to join table A 3 times to give the following
result

      1st    2nd     3rd
Row1    1      2       4
Row2    1      2       5
Row3    1      3       6

But can I show
a. which level each node belongs
b. no. of child nodes it has
altogether in one "select" sql

and if the level exceeds 3, how can I do it?


Many thanks.....


Best regards,
Boris

pgsql-general by date:

Previous
From: Herbert Liechti
Date:
Subject: Re: How I can undelete recodes?
Next
From: Tom Lane
Date:
Subject: Re: vacuum messges