stumped on a with recursive example - Mailing list pgsql-novice

From Henry Drexler
Subject stumped on a with recursive example
Date
Msg-id CAAtgU9TxRQBkNDAh=UD7WHLSCnVaOVcjrM6+6LBFw8NmmbfLNQ@mail.gmail.com
Whole thread Raw
Responses Re: stumped on a with recursive example
List pgsql-novice
on http://wiki.postgresql.org/wiki/CTEReadme

It shows this:

INSERT INTO department (id, parent_department, "name")
VALUES    (0, NULL, 'ROOT'),    (1, 0, 'A'),    (2, 1, 'B'),    (3, 2, 'C'),    (4, 2, 'D'),    (5, 0, 'E'),    (6, 4, 'F'),    (7, 5, 'G');

-- department structure represented here is as follows:
--
-- ROOT-+->A-+->B-+->C
--      |         |
--      |         +->D-+->F
--      +->E-+->G

I have ran the recursive query and indeed it only is showing A,B,C,D,F and not E,G as shown in the graphic above.  So postgres is understanding the structure - however I am not.  

What I am not getting/seeing is how one is getting the F to come after the D and the G after the E.

  I can see A and E both have a 0 so they branch off of the Null, but why is the 4,'F' being attached to the 2,'D' and the 5,'G' being attached to the 0,'E'?












pgsql-novice by date:

Previous
From: Yangyang
Date:
Subject: Why tuning is not giving better performance?
Next
From: Johan Nel
Date:
Subject: Re: stumped on a with recursive example