Re: Categories and Sub Categories (Nested) - Mailing list pgsql-general

From Michael Glaesemann
Subject Re: Categories and Sub Categories (Nested)
Date
Msg-id 71F2D761-D274-4453-8418-BEB2706503C0@myrealbox.com
Whole thread Raw
In response to Categories and Sub Categories (Nested)  ("Martin Kuria" <martinkuria@hotmail.com>)
List pgsql-general
On Apr 19, 2006, at 14:44 , Martin Kuria wrote:

> I have a postgresql database Table Categories which has the
> structure like this
>
> Cat_ID | Parent_ID | Name
> ------------------------------------
> 1 | 0 | Automobiles
> 2 | 0 | Beauty & Health
> 3 | 1 | Bikes
> 4 | 1 | Cars
> 5 | 3 | Suzuki
> 6 | 3 | Yamaha
> 7 | 0 | Clothes
>
> According to the above Database data, Suzuki and Yamaha are the
> Subcategories of Category Bikes and Bikes in turn is the
> Subcategory of Automobiles.

If you're looking at having a potentially deep hierarchy, I'd
recommend taking a look at nested sets, which also allows you to keep
everything in one table.

http://www.intelligententerprise.com/001020/celko.jhtml?
_requestid=145525]

By the way, the method you outline above is often called the
adjacency list model.

Hope this helps.

Michael Glaesemann
grzm myrealbox com




pgsql-general by date:

Previous
From: Michael Glaesemann
Date:
Subject: Re: How to implement a "subordinate database"?
Next
From: Don Y
Date:
Subject: I18N