Q: Tree traversal with SQL query? - Mailing list pgsql-general

From Adrian von Bidder
Subject Q: Tree traversal with SQL query?
Date
Msg-id 200706151020.33155.avbidder@fortytwo.ch
Whole thread Raw
Responses Re: Q: Tree traversal with SQL query?  (Alban Hertroys <alban@magproductions.nl>)
List pgsql-general
Hi,

Is there any way to do tree traversal with only one SQL query (no
procedure/function)?

CREATE TABLE foo (
  node INTEGER,
  parent INTEGER REFERENCES foo(node)
);

Ideally the output would be a depth-first tree traversal starting at root
(marked by parent == node, for example.)

Obviously, I can do this with "normal" programming and loops, but it bugged
me a while if its at all possible doing this in one query.

cheers
-- vbi

--
Available for key signing in Zürich and Basel, Switzerland
                    (what's this? Look at http://fortytwo.ch/gpg/intro)

pgsql-general by date:

Previous
From: "Albe Laurenz"
Date:
Subject: Re: DeadLocks...
Next
From: Adrian von Bidder
Date:
Subject: "Constant" fields in a table