473,406 Members | 2,467 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 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 2615
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: ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.