From: Frank Joerdens <frank@joerdens.de>
To: Stuart Statman <stu@slammedia.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: How to represent a tree-structure in a relational database
Date: Wed, 13 Dec 2000 23:25:14 +0100
Message-ID: <20001213232514.A31376@rakete.joerdens.de> (raw)
In-Reply-To: <NEBBJLPJHKIDLJDGCMKAKEIDCBAA.stu@slammedia.com>
References: <3A379A5F.97FFAF01@joerdens.de>
<NEBBJLPJHKIDLJDGCMKAKEIDCBAA.stu@slammedia.com>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: frank@joerdens.de, stu@slammedia.com
Subject: Re: How to represent a tree-structure in a relational database
In-Reply-To: <20001213232514.A31376@rakete.joerdens.de>
References: <3A379A5F.97FFAF01@joerdens.de> <NEBBJLPJHKIDLJDGCMKAKEIDCBAA.stu@slammedia.com> <20001213232514.A31376@rakete.joerdens.de>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox