Re: Get A Tree from a table - Mailing list pgsql-sql

From Josh Berkus
Subject Re: Get A Tree from a table
Date
Msg-id web-1773971@davinci.ethosmedia.com
Whole thread Raw
In response to Get A Tree from a table  (gzscott2001@yahoo.ca (Scott Yaung))
List 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/



pgsql-sql by date:

Previous
From: Jean-Luc Lachance
Date:
Subject: Re: enforcing with unique indexes..
Next
From: Joe Conway
Date:
Subject: Re: Get A Tree from a table