From: | Henry Drexler <alonup8tb(at)gmail(dot)com> |
---|---|
To: | PGSQL-Novice <pgsql-novice(at)postgresql(dot)org> |
Subject: | stumped on a with recursive example |
Date: | 2011-12-02 15:12:52 |
Message-ID: | CAAtgU9TxRQBkNDAh=UD7WHLSCnVaOVcjrM6+6LBFw8NmmbfLNQ@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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'?
From | Date | Subject | |
---|---|---|---|
Next Message | Johan Nel | 2011-12-02 15:29:44 | Re: stumped on a with recursive example |
Previous Message | Yangyang | 2011-12-01 18:00:30 | Why tuning is not giving better performance? |