Re: Argument for 1NF by counter-example
Date: 31 Oct 2004 19:05:45 -0800
Message-ID: <4b45d3ad.0410311905.759ab576_at_posting.google.com>
>>> If it can query relational db's that contain hierarchical data >>> then people would start to use it. >>> >> Could you give a small example of hierarchal data/query that is >> difficult in RM that people would like XML/XQuery to solve? >> > Probably anything that the SQL "WITH RECURSE" clause provides, the ability > to walk a hierarchy and produce a flattened relation. The employee > organizational chart is as good a common example as any.
While XDb2 is neither RM or XML/XQuery, below is an example of creating/walking an employee hierarchy. Each person is given a simple name that reflects his level in the hierarchy to make it easier to follow however a person's name could be anything. Note that person z has several bosses.
a
a1
a1a
a1b
z
a2
a2a
a2b
z
a3
z
// Below script represents the above things/hierarchy
CREATE2 *person.cls = thing; CREATE2 *a.cls = person; CREATE2 *a1.cls = person; CREATE2 *a1a.cls = person; CREATE2 *a1b.cls = person; CREATE2 *a2.cls = person; CREATE2 *a2a.cls = person; CREATE2 *a2b.cls = person; CREATE2 *a3.cls = person; CREATE2 *a3a.cls = person; CREATE2 *z.cls = person;
// Create verbs to relate persons
CREATE2 *boss.cls = verb;
CREATE2 boss.vbType = kr; // boss leads to higher level in hier
CREATE2 *employee.cls = verb;
CREATE2 employee.vbType = cr; // employee leads to lower level in hier
CREATE2 boss.opposite = employee;
// Create hierarchy
CREATE2 a.employee = a1;
CREATE2 a1.employee = a1a; CREATE2 a1.employee = a1b; CREATE2 a1.employee = z;
CREATE2 a.employee = a2;
CREATE2 a2.employee = a2a;
CREATE2 a2.employee = a2b;
CREATE2 a2b.employee = z;
CREATE2 a.employee = a3;
CREATE2 a3.employee = z;
// Select a's immediate employees
SELECT2 a.employee = %;
// Select a's employees and their employees recursively
SELECTR a.employee;
// Select a's distinct employees recursively
// Note: Distinct works if a is root of employee hierarchy
SELECTRD a.employee;
// Select z's bosses recursively
SELECTR z.boss;
// SELECTR and SELECTRD call function T_Relative()
// which is exposed via API
while(x = T_Relative(pAThing, pVerb, distinct_b){
// do stuff
}
Received on Mon Nov 01 2004 - 04:05:45 CET