| Oracle FAQ | Your Portal to the Oracle Knowledge Grid | |
Home -> Community -> Usenet -> comp.databases.theory -> Re: The stupidest design I ever saw
Neo wrote:
> > table Nodes (id number, ... -- content)
> > table Edges (tail number, head number, ... -- more content, if edges are labeled)
>
> How do I use the above schema to model the vehicle classes shown in the
> RDF example given earlier? I still don't see it.
No, you first please demonstrate that the above classification serves some useful purpose.
I prefer to write a database schema for cities and travel links instead. Here we go:
table Cities (
name string
)
table Connections (
tail string,
head string,
distance integer
)
Example query: find the shortest path between two cities.
Surprisingly, it's not easy to express this or parts explosion kind of query in XQuery (which is allegedly a superior tool for graph/tree related problems). You can compare XQuery solution
define function total (element PART $part)
returns element PART {
let $subparts := $part/PART/total(.)
return
<PART NAME="$part/@NAME"
COST="$part/@COST + sum($subparts/@COST)">{
$subparts
}</PART>
}
from
http://homepages.inf.ed.ac.uk/wadler/papers/xquery-afp/xquery-afp-slides.pdf
with SQL (which I just mindlessly copying and pasting from my book without really making sure they accomplish the same thing):
select leaf, sum(factoredQuantity) from (
select product(Quantity) factoredQuantity,
first(Part) root, last(SubPart) leaf
from AssemblyEdges
connect by prior Part = later SubPart
) where root = 'Bicycle'
group by leaf
Received on Wed Apr 05 2006 - 21:55:45 CDT
![]() |
![]() |