Help with a "recursive" query

From: alet(at)unice(dot)fr (Jerome Alet)
To: pgsql-sql(at)postgresql(dot)org
Subject: Help with a "recursive" query
Date: 2002-06-19 07:30:21
Message-ID: 20020619073021.GA2374@port50-2.unice.fr
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hi,

I've got a table like this :

id parent description
01 00 xxxxxx
02 00 xxxxxx
03 01 xxxxxx
04 02 xxxxxx
05 01 xxxxxx
06 05 xxxxxx
07 03 xxxxxx
08 07 xxxxxx
09 00 xxxxxx
10 02 xxxxxx

I want to get all tuples which have id=01 as their parent
or ancestor, i.e. :

03, 05, 06, 07, 08

this to represent a sort of n-tree :

01
/ \
/ \
/ \
03 05
/ \
/ \
/ \
07 06
|
|
|
08

this example is simple because each node has at most one child, but in
my real data there's no such limit.

any idea ?

thanks in advance

Jerome Alet

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Achilleus Mantzios 2002-06-19 07:44:03 Re: text vs varchar
Previous Message Josh Goldberg 2002-06-19 01:28:55 Re: text vs varchar