Re: Get A Tree from a table

From: "Josh Berkus" <josh(at)agliodbs(dot)com>
To: gzscott2001(at)yahoo(dot)ca (Scott Yaung), pgsql-sql(at)postgresql(dot)org
Subject: Re: Get A Tree from a table
Date: 2002-10-07 16:40:37
Message-ID: web-1773971@davinci.ethosmedia.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Scott,

> NODES__________________________________
> ParentID Varchar(20)
> ParentType varchar(20)
> ChildID varchar(20)
> ChildType varchar(20)

This looks difficult... mainly becuase, in your shema, a "parent" node
can be its own child or grandchild, resulting in an endless loop.

If that was not your intention, you may wish to think of using a
different structure.

There are two main ways for you to approach this problem in 7.2.x:
1) Buy Joe Celko's "SQL for Smarties" and read up on pure-SQL tree
implementations, which he covers in far more depth than I want to here;
2) Explore the tree module in /contrib in your Postgresql source.

I understand from Joe Conway that in 7.3, you will have another choice,
as Postgres will offer support for Oracle's tree-like "IS CONNECTED BY"
expression.

Good luck!

-Josh Berkus

P.S. also, there's some articles on tree structures up at techdocs:
http://techdocs.postgresql.org/

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Joe Conway 2002-10-07 16:54:22 Re: Get A Tree from a table
Previous Message Jean-Luc Lachance 2002-10-07 15:55:10 Re: enforcing with unique indexes..