Skip site navigation (1) Skip section navigation (2)

stumped on a with recursive example

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: (view raw, whole thread or download thread mbox)
Lists: pgsql-novice

It shows this:

INSERT INTO department (id, parent_department, "name")
     (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

Next:From: Johan NelDate: 2011-12-02 15:29:44
Subject: Re: stumped on a with recursive example
Previous:From: YangyangDate: 2011-12-01 18:00:30
Subject: Why tuning is not giving better performance?

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group