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'?