Re: Recursive select

Keith Gray <keith@heart.com.au>

From: Keith Gray <keith@heart.com.au>
To: Jason Kwok <jason@newhonest.com>
Cc: pgsql-sql@postgresql.org
Date: 2001-10-29T22:09:31Z
Lists: pgsql-sql
Jason Kwok wrote:
> 
> I have a table :
> 
> MyID           parentID
> ================
> 5                    6
> 6                    7
> 3                    13
> 7                    3
> 
> Is there any simple select statement that can get all rows with MyID = 5 and
> all its parents?
> That means 5's parenet is 6, 6's parent is 7, 7's parent is 3.....
> 

I had a similar problem a couple of weeks back.
The only way I could get around it was "programmatically".
This is an iterative (loop) problem.

Because I am writing for several brands/flavours of database
I solved it in VB, but some solutions (for postgres only)
are offered using functions or triggers in PgSQL.

-- 
Keith Gray

Technical Development Manager
Heart Consulting Services P/L
mailto:keith@heart.com.au