473,698 Members | 2,378 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Selecting All Parents in a Path Enumerated Tree

Hi,

I have a tree structure which is maintained through the use of a path
enumerated column:

CREATE TABLE items (
item_id NUMERIC NOT NULL,
path VARCHAR2(64) NOT NULL
);

The path is is a colon separated list of ids of the nodes of the tree.
So, for example, in this structure:

0 -> 1 -> 2 -> 3 -> 4

item id 4 would have a path of '0:1:2:3' (0 is the root of all
items, and does not actually exist). Notice that the path does not
include the item's own id.

I would like to select all of the items in a given item's path:

SELECT id, path FROM items WHERE id IN (PATH_TO_IDS(pa th));

or maybe:

SELECT id, path FROM items WHERE PATH_EQUALS(id, path));

or maybe something else altogether. This should return:

ITEM_ID PATH
------- -------
1 0
2 0:1
3 0:1:2
4 0:1:2:3
Jul 20 '05 #1
1 2483
You're going to have to parse the path in order to use the nodes as keys;
here is an anchor to a function that can do it (you'll have to modify it to
use colons; it's set up for commas). I recommend that you read the rest of
the article as well...

http://www.sommarskog.se/arrays-in-sql.html#tblnum-core

"Ones Self" <nu******@sneak email.com> wrote in message
news:a2******** *************** ***@posting.goo gle.com...
Hi,

I have a tree structure which is maintained through the use of a path
enumerated column:

CREATE TABLE items (
item_id NUMERIC NOT NULL,
path VARCHAR2(64) NOT NULL
);

The path is is a colon separated list of ids of the nodes of the tree.
So, for example, in this structure:

0 -> 1 -> 2 -> 3 -> 4

item id 4 would have a path of '0:1:2:3' (0 is the root of all
items, and does not actually exist). Notice that the path does not
include the item's own id.

I would like to select all of the items in a given item's path:

SELECT id, path FROM items WHERE id IN (PATH_TO_IDS(pa th));

or maybe:

SELECT id, path FROM items WHERE PATH_EQUALS(id, path));

or maybe something else altogether. This should return:

ITEM_ID PATH
------- -------
1 0
2 0:1
3 0:1:2
4 0:1:2:3

Jul 20 '05 #2

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

Similar topics

1
2203
by: Alastair Cameron | last post by:
I have a VB (VB6, not .NET) application that reads an XML file (using MSXML v3.2 parser); the XML file contains a reference to an external DTD. The DTD has numerous enumerated attribute declarations like so: <!ATTLIST MyElement MyAttribute (One | Two | Three) "One" > The VB code needs to generate dynamic pick-list for all the attributes that
0
1093
by: David R. Throop | last post by:
How does one progressively restrict enumerated types in Owl? I've got an ontology of function-terms. I want to map English-language terms (as strings) to the function terms. I want to restrict the mapping as I go down the hierarchy. In the (very stripped down) example, FUNCTION can map to any of the four terms, but its sub-sub-subclass INCREASE_QUANTITY only maps to 'produce.' FUNCTION Hierarchy MAPPED TERMS
2
23377
by: Rob Cowie | last post by:
Hi, Given a string representing the path to a file, what is the best way to get at the filename? Does the OS module provide a function to parse the path? or is it acceptable to split the string using '/' as delimiters and get the last 'word'. The reason I'm not entirely happy with that method is that it is platform specific. I would prefer to use a built in method if possible. Cheers,
3
2250
by: Tzvika Barenholz | last post by:
Hi all. Here's my problem: I have a tree linking macaddresses (bigints) in a tree structure. i want to get the path from node a to b. create table tree1(father bigint , child bigint); insert into tree1 (father,child) values (100,200); insert into tree1 (father,child) values (100,300); insert into tree1 (father,child) values (100,400);
6
1978
by: Sigmathaar | last post by:
Hi, while making an XML parser for the creation of an entire directory list I got this problem and I'm having trouble solving it. The program (not yet written) goes through an XML Schema Instance to create some directories (about 5000). While creating the directories the XML file that I'm parsing is alphabetically ordered not hierarchically and I can't allow the program to stock the path names for each brach on the directory tree. The...
4
11962
by: James L | last post by:
I have a tree view with a root, 3 noodes(1,2,3) each having one sub node. I drill down to a node. I get the path by saying treeView1.selectedNode.fullpath and assign it to a variable. If I redraw the tree, or close it up and want to expand the same node again, can i do this via the path?
2
2390
by: James L | last post by:
I have finally developed some code that allows you to re populate a tree view and re select the last node that was clicked. However, you have to hard code it for the number of levels the tree view could possibly be expanded to. Any ideas? //The test program has a button to set the path and a button to execute the path finding code. //This is so that you can close the treeview back up to the root to ensure the correct code is selected
1
1547
by: jdhcards | last post by:
Hello, I've been banging my head against a problem all day without a solution, and I'm hoping you all can help. I've got a piece of XML that defines a set of elements in a flat list. Each of these elements has an attribute "Id" which has a unique value. Some of these elements have a parent-child relationship, specified with a "ResultId" attribute in one of the child nodes. <element id=1>
3
3326
by: krzysztof.konopko | last post by:
Hello! I want to design a class hierarchy with one base abstract class, let's say CBase. I have a predicate that every object in the class hierarchy must have a parent object of type from this class hierarchy but only objects of some of these types can be a parent. Example: class CFruit : public CBase { }; class CBranch : public CBase { };
0
8676
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8608
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9161
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8867
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6522
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4370
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3050
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2332
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2006
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.