Re: [GENERAL] Implementing hierarchy

From: Chris Bitmead <chris(dot)bitmead(at)bigfoot(dot)com>
To: pgsql-general(at)postgreSQL(dot)org
Subject: Re: [GENERAL] Implementing hierarchy
Date: 1999-06-03 06:00:32
Message-ID: 37561A00.8D783862@bigfoot.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I have a similar problem. I can tell you how to get subcategories and
sub-sub categories with unions and self-joins, but it sounds like you've
already worked that out. I don't know how to get sub-categories down to
an arbitrary depth (I think this is the crux of your question), so I
have joins that go down several levels, as many as I need.

Mike Frisch wrote:
>
> 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)
>
> Is it possible to formulate an SQL query to give me the hierarchy for SCA
> hard drives? (with "Computer Hardware", "Hard Drives", "SCSI", "SCA" in
> the result set) I've been experimenting with self-joins, but cannot see
> how to extend it for an arbitrary number of subcategories. If I have the
> primary key for an item listed as being an "SCA hard drive", how do I get
> it's parents (subcategories and toplevel parent)?
>
> Pointers to documentation/books/web sites with this sort of information
> are greatly appreciated.
>
> Much thanks in advance.
>
> Mike.
>
> ======================================================================
> Mike Frisch Email: mfrisch(at)saturn(dot)tlug(dot)org
> Northstar Technologies WWW: http://saturn.tlug.org/~mfrisch
> Newmarket, Ontario, CANADA
> ======================================================================

Browse pgsql-general by date

  From Date Subject
Next Message Laurence Liew 1999-06-03 06:03:00 Parallelizing PostgreSQL for Cluster
Previous Message Chris Bitmead 1999-06-03 05:56:34 Re: [GENERAL] Implementing hierarchy