Re: [GENERAL] Implementing hierarchy - Mailing list pgsql-general

From
Subject Re: [GENERAL] Implementing hierarchy
Date
Msg-id 14167.2065.219096.997269@c837917-a.potlnd1.or.home.com
Whole thread Raw
List pgsql-general
Rob Walker writes:
 > > I am trying to write code to access a product catalog (more as a learning
 > > exercise than anything else) and need to implement some sort of searchable
 > > hierarcy.  For example:
 > >
 > > Computer Hardware (toplevel)
 > >    Hard Drives
 > >       Internal
 > >          SCSI
 > >             Fast SCSI
 > >             Wide SCSI
 > >             SCA
 > >
 > > Assuming these 'categories' are all in the same table as follows:
 > >
 > > prkey (primary key)
 > > descr varchar
 > > parent (for subcategories, toplevel parent is 0)
 >
 > I don't know if there is a 'right' way to do this, but I have done something
 > similar having an extra table that contains a tuple listing (node, ancestor)
 > pairs.  This is kept in sync with the main table using a couple of triggers.
 > The code is at the end
 >
 > A sequence is used for the primary key in the main table, and the hierarchy
 > is then implicit since you can't create a child before the parent (at least
 > my application doesn't let you move an existing child to another parent).

Here is a web page that may help. It explains something along the same
lines.

http://www.dbmsmag.com/9809d05.html

--
Patrick D. Logan        mailto:patrickdlogan@home.com

pgsql-general by date:

Previous
From: doctor@fruitbat.org
Date:
Subject: Re: [GENERAL] RE: [PORTS] AIX-4.2.1 binaries ? more info. PLEASE
Next
From: Chris Bitmead
Date:
Subject: Re: [GENERAL] Parallelizing PostgreSQL for Cluster