Forum OpenACS Development: Hierarichal Trees With No cyclic

Collapse
Posted by roohie natt on
th erequirement is that the table
id pid
1 0
2 1
3 1
4 0
5 4

if we want to create a new node in the tree under 3
then it cannot have the child node as its upper level nodes
i.e if 1 has 2 as a child node then 2 can't have 1 as child node or any other already existing node in the tree resulting in cyclic tree
it can have another tree as its child node

Sujjest the Query ASAP

Collapse
Posted by Tom Jackson on
Is it possible you are taking an intro course in SQL?

Anyway, the answer is that you would need a procedural language function to enforce this constraint.

There are probably many better places to ask this question, even the Q&A Forum here at OpenACS would be better, but maybe an open source db forum somewhere. Suggestions, anyone?

The main problem with the question is that hierarchies in SQL don't exist, they are invented by the end user. You decide, by repeated application of a query, what hierarchy exists between objects.

If this question goes along with the previous one you asked about, with the ordering of parent, child, grandchild, then the easy intro SQL course answer is to enforce the child id to be greater than the parent id.

Collapse
Posted by roohie natt on
Well its known that procedure would be required
but the requriement dosent allow to work in PL/SQL
so just the sujjestions were welcomed if anything could be done in SQL

about taking an course in SQL .its not forum to answer such question

It was just that the exact forum was not known where the
questions could be posted.
But had quite nice responses here.

Collapse
Posted by Gustaf Neumann on
Look at "CONNECT BY" in Oracle
http://www.adp-gmbh.ch/ora/sql/connect_by.html

Simple Introduction to the WITH clause in SQL99
http://www.teradata.com/tdmo/v06n03/Tech2Tech/InsidersWarehouse/OddballSQLTricks.aspx

For a comparison of Oracles "CONNECT BY" with SQL99 WITH look here
http://gppl.moonbone.ru/

a patch for postgresql to implement SQL99 (up to 8.2) is here
http://gppl.moonbone.ru/

look a ltree:
http://www.sai.msu.su/~megera/postgres/gist/ltree/

look at:
http://people.planetpostgresql.org/merlin/index.php?/archives/2-Dealing-With-Recursive-Sets-With-PLPGSQL.html