472,958 Members | 2,639 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 software developers and data experts.

simple tree in postgress

Hi, I'm a novice to postgress and need to constract a simple tree.
In my table I have:

regionID int
parentID int
name char

I need to do two functions: find all the children of XXX parent and
find if an item is a child of an XXX parent.

I've looked in the discussions and I think there are at least two ways
of doing it:

(I'm pasting the following from one of the threads)

category_id | parent_id | sort_key | name
-------------+-----------+----------+---------------------
0 | | aa | Top
10 | 0 | aaab | Propaganda
43 | 10 | aaabaa | Quotes
12 | 10 | aaabab | Presentations
70 | 10 | aaabai | Waivers
4 | 10 | aaabaj | Legislation
54 | 4 | aaabajaa | Youth in Politics
36 | 10 | aaabak | Statistics

This looks easy and I can see how to write queris using 'LIKE' on a
sort_key

The other way is to do preorder, inorder or postorder travrsals and
describe the level of the item and its traversal sequence number. The
example I found was a bit confusing. Can you point me to a place
where I can find more examples/explanations.

Are there other ways of doing it? My tree would be small, maybe 5 - 7
levels and not too many leaves. What are the advantages/disadvantages
of each method?
Is there a better way? Does postgress offer any built in
functions/packages to work with simple trees?
I appreciate your advice.
Thank you
N.K.
Jul 19 '05 #1
1 2573
In article <3f**************************@posting.google.com >,
nk*****@optonline.net (Liza) wrote:
Hi, I'm a novice to postgress and need to constract a simple tree.
In my table I have:

regionID int
parentID int
name char

I need to do two functions: find all the children of XXX parent and
find if an item is a child of an XXX parent.

I've looked in the discussions and I think there are at least two ways
of doing it:

(I'm pasting the following from one of the threads)

category_id | parent_id | sort_key | name
-------------+-----------+----------+---------------------
0 | | aa | Top
10 | 0 | aaab | Propaganda
43 | 10 | aaabaa | Quotes
12 | 10 | aaabab | Presentations
70 | 10 | aaabai | Waivers
4 | 10 | aaabaj | Legislation
54 | 4 | aaabajaa | Youth in Politics
36 | 10 | aaabak | Statistics

This looks easy and I can see how to write queris using 'LIKE' on a
sort_key

The other way is to do preorder, inorder or postorder travrsals and
describe the level of the item and its traversal sequence number. The
example I found was a bit confusing. Can you point me to a place
where I can find more examples/explanations.

Are there other ways of doing it? My tree would be small, maybe 5 - 7
levels and not too many leaves. What are the advantages/disadvantages
of each method?
Is there a better way? Does postgress offer any built in
functions/packages to work with simple trees?
I appreciate your advice.
Thank you
N.K.


Liza, there is an excellent series of articles by Joe Celko on how to
use SQL for tree structures. I got his method working about a yr. ago
and dig it up for an example if you need it.

The articles start at:
http://www.intelligententerprise.com...celko1_1.shtml

Boyd

Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Terry | last post by:
Hi, This is a newbie's question. I want to preload 4 images and only when all 4 images has been loaded into browser's cache, I want to start a slideshow() function. If images are not completed...
6
by: sathyashrayan | last post by:
#include<stdio.h> #include<stdlib.h> #include<string.h> struct tree { int data; struct tree *left,*right; }; void init(struct tree *node)
67
by: Bob Powell | last post by:
To whom it may concern: I find the recent articles in various trade publications a little disturbing due to the lack of PostgrSQL mention. I continue to see articles about how IBM may be...
1
by: Liza | last post by:
Hi, I'm a novice to postgress and need to constract a simple tree. In my table I have: regionID int parentID int name char I need to do two functions: find all the children of XXX parent...
1
by: Praveen | last post by:
Hi All, Can anybody tell from where i can download the latest Postgress Windows version? Thanks, Praveen
1
by: hn.ft.pris | last post by:
I have the following code: Tree.h defines a simple binary search tree node structure ########## FILE Tree.h ################ #ifndef TREE_H #define TREE_H //using namespace std; template...
5
gekko3558
by: gekko3558 | last post by:
I am writing a simple binary search tree (nodes are int nodes) with a BSTNode class and a BST class. I have followed the instructions from my C++ book, and now I am trying to get a remove method...
4
by: Travis | last post by:
I'm creating a real simple tree. No sorting and every node can have infinite children. // TreeNode.h #ifndef TREENODE_H #define TREENODE_H #include <iostream> #include <iomanip>
1
by: HighBuddha | last post by:
Hello, i have a question about game trees. I've been given an assignment in class (highschool) and the assignment is to write a program the simulates The Game Of Eight. The game runs like this: ...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.