Database Management
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesDatabase Management

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old July 31st, 2003, 03:38 PM
Jabol Jabol is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Poland
Posts: 57 Jabol User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 28 m 57 sec
Reputation Power: 6
Tree Structure. How?

Hi
I just wondered what would be the best way to make a tree structure (filesystem) in database (postgresql in my case, but it's a general question).

The best way I can think of for now is to do a structure like that:
Code:
nodes:
id INT
parent_id INT
name VARCHAR( LIMIT )
type BIT(2) -- 00 for file, 01 for directory, (links are optional) 10 for link to file and 11 for link to directory

files:
id INT
content TEXT

links: -- optional as I said
from_id INT
to_id INT

I want it (structure) to be optimalised for the things like that:
select all from a directory with a specified path/id
insert/select a file using path/id
read a whole directory and all subdirectories and all their subdiretories etc. etc. using path/id

I won't be using any of listed below often so they don't need to be vary fast:
getting path using id
moving directories/files

It's the best way to do this if you ask me, but maybe I'm just too tired so say what do you think.

Reply With Quote
  #2  
Old July 31st, 2003, 06:06 PM
rycamor rycamor is offline
Gödelian monster
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jul 1999
Location: Pembroke Pines, Florida, USA
Posts: 2,300 rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 3 h 2 m 4 sec
Reputation Power: 44
Check out our discussion of Graph representation in database. In it, we also discussed trees. Especially of interest to you should be the "materialized path" approach. Also, there is apparently an add-on to PostgreSQL in the 'contrib' section to imitate Oracle/MSSQL CONNECT BY syntax for adjacency list handling of tree data.

Enjoy
__________________
The real n-tier system:

FreeBSD -> PostgreSQL -> [any_language] -> Apache -> Mozilla/XUL

Amazon wishlist -- rycamor (at) gmail.com

Reply With Quote
  #3  
Old August 1st, 2003, 06:25 AM
Jabol Jabol is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Poland
Posts: 57 Jabol User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 28 m 57 sec
Reputation Power: 6
thx for link

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesDatabase Management > Tree Structure. How?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway