Skip site navigation (1) Skip section navigation (2)

Re: Categories and Sub Categories (Nested)

From: Michael Glaesemann <grzm(at)myrealbox(dot)com>
To: Martin Kuria <martinkuria(at)hotmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Categories and Sub Categories (Nested)
Date: 2006-04-20 00:39:00
Message-ID: 71F2D761-D274-4453-8418-BEB2706503C0@myrealbox.com (view raw or flat)
Thread:
Lists: 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




In response to

pgsql-general by date

Next:From: Orion HenryDate: 2006-04-20 02:39:45
Subject: primary keys
Previous:From: Michael GlaesemannDate: 2006-04-20 00:14:44
Subject: Re: How to implement a "subordinate database"?

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group