Q: Tree traversal with SQL query?

From: Adrian von Bidder <avbidder(at)fortytwo(dot)ch>
To: pgsql-general(at)postgresql(dot)org
Subject: Q: Tree traversal with SQL query?
Date: 2007-06-15 08:20:32
Message-ID: 200706151020.33155.avbidder@fortytwo.ch
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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)

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Adrian von Bidder 2007-06-15 08:24:26 "Constant" fields in a table
Previous Message Albe Laurenz 2007-06-15 07:51:21 Re: DeadLocks...