From: | Frank Joerdens <frank(at)joerdens(dot)de> |
---|---|
To: | Stuart Statman <stu(at)slammedia(dot)com> |
Cc: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: How to represent a tree-structure in a relational database |
Date: | 2000-12-13 22:25:14 |
Message-ID: | 20001213232514.A31376@rakete.joerdens.de |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
On Wed, Dec 13, 2000 at 11:38:18AM -0800, Stuart Statman wrote:
[ . . . ]
> I would suggest, instead, to create a table that represents your hierarchy
> without adding columns. For example :
>
> create table Category (
> CategoryID int4 not null primary key,
> ParentCategoryID int4 not null REFERENCES Category (CategoryID),
> CategoryName varchar(100)
> );
>
> Add a CategoryID with an FK reference to this table, and your work is done.
>
> Then adding, inserting, removing, or moving layers in the hierarchy becomes
> quite simple. This also preserves hierarchical integrity, where subcategory
> a of subcategory b will also remain a subcategory of category c if
> subcategory b is a subcategory of subcategory c, where I'm not sure your
> model will preserve or guarantee that. (Does that sentence deserve a prize?)
Cool. That looks like my solution. I had actually seen it someplace
before, but didn't make the connection with my problem.
Ta, Frank
From | Date | Subject | |
---|---|---|---|
Next Message | Frank Joerdens | 2000-12-13 22:28:12 | Re: How to represent a tree-structure in a relational database |
Previous Message | clayton cottingham | 2000-12-13 22:16:08 | Re: How to represent a tree-structure in a relational database |