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

Re: [GENERAL] Tree structure

From: "K(dot)T(dot)" <kanet(at)calmarconsulting(dot)com>
To: "Kaare Rasmussen" <kar(at)webline(dot)dk>, <pgsql-general(at)postgreSQL(dot)org>
Subject: Re: [GENERAL] Tree structure
Date: 1999-02-26 11:44:50
Message-ID: 001001be617d$6c5ea1e0$6adaa5ce@p2-400-death (view raw, whole thread or download thread mbox)
Lists: pgsql-general
Its been a while since I wrote this and its kinda fuzzy at this hour, but
this will give you a general direction to go and you can work out the
If you know the depth of the tree then you can create a field of a specified
length and store something like:

tree_field varchar(16)

This allows you to select all records that are in level "B" fairly easily
with a "like" clause.  Note that everything has a root of "A".

Or you can create two fields:


This one is confusing and there is no easy way to show the tree in text.
You cannot use the same number for a node. eg.  if your first level is "A"
then none of your sub levels can be "A".  So use the sequence generator to
generate a unique key for each node.  Then your select would look something
like this:
   Select * from hierachy_table where parent_key = child_key and parent_key
= "A";
This should give you all branches under the "A" node.  To get the
indention...hmmm try ordering the records by parent/child and writing code
that loops thru the records?  That one stumps me...gotta sleep on it :)

DISCLAIMER:  This might not be 100% accurate...its a seat of the pants
memory.  Anyone who knows this please feel free to correct my errors :)

-----Original Message-----
From: Kaare Rasmussen <kar(at)webline(dot)dk>
To: pgsql-general(at)postgreSQL(dot)org <pgsql-general(at)postgreSQL(dot)org>
Date: Friday, February 26, 1999 3:02 AM
Subject: [GENERAL] Tree structure

>I can't figure this one out. I need a tree structure like this
>Number  Pointer
>1            0
>2            1
>3            1
>4            2
>5            0
>6            1
>7            5
>This should somehow show up like this
>The whole excercise is because I'd like to show a tree structure:
>- 2
>- - 4
>- 3
>- 6
>- 7
>Is this possible with PostgreSQL?

pgsql-general by date

Next:From: Roderick A. AndersonDate: 1999-02-26 13:40:27
Subject: SQL/Relational Design Text Book recommendations
Previous:From: Peter T MountDate: 1999-02-26 11:00:30
Subject: Re: [GENERAL] Tree structure

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