Re: Recursive select

From: Roberto Mello <rmello(at)cc(dot)usu(dot)edu>
To: Jason Kwok <jason(at)newhonest(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Recursive select
Date: 2001-10-29 22:47:54
Message-ID: 20011029154754.A11730@cc.usu.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Fri, Oct 26, 2001 at 02:57:18PM +0800, 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?

Dan Wickstrom, of the OpenACS.org team, implemented a bunch of PL/pgSQL
functions to do what you're after. It simulates the CONNECT BY behaviour
in Oracle.

OpenACS 4 is GPL'd, so you can look at the source. I need to extract the
relevant sections and post them in the PostgreSQL Cookbook (actually, I
think there are a couple tree functions in there -
http://www.brasileiro.net/postgres/)

-Roberto
--
+----| http://fslc.usu.edu USU Free Software & GNU/Linux Club |------+
Roberto Mello - Computer Science, USU - http://www.brasileiro.net
http://www.sdl.usu.edu - Space Dynamics Lab, Developer
Always forgive your enemies. They hate that!

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Roberto Mello 2001-10-29 22:50:23 Re: SQL99
Previous Message Keith Gray 2001-10-29 22:09:31 Re: Recursive select