i think this kind of thing is more suited to the "nested sets" model for trees. a google will show you a million hits, heres one:
http://dev.mysql.com/tech-resources/articles/hierarchical-data.html im not a fan of "nested sets" because theres a huge overhead to changing nodes (requires updates of 50% of the rows) and it doesnt suit what I generally use trees for, which is instead of one huge tree, many smaller trees which correspond to some document-oriented concept like an XML document or something, that I read fully into an object structure anyway. but if youre doing math type stuff nested sets probably better. On Mar 15, 2007, at 10:25 AM, svilen wrote: > > There is some graph - represented as edges in some assoc.table, and > they having some associated item with them (e.g. weight or length). > > Is it possible to calculate the overall lenght of path from node to > node (if there is a path at all) in SQL? > > Finding if there is a path in the graph from node1 to node2, with max, > say, 2 hops will look like: > FROM node as node1, node as node2, node as node3 > link as link1, link as link2 > SELECT link1.length, > WHERE node1.id == link1.in AND node2.id == link1.out ##1 hop > OR node1.id == link1.in AND node2.id == link1.out > AND node2.id == link2.in AND node3.id == link2.out ##2 hops > > but i dont see how to also sum the link.length. or should i use UNION > instead of OR? > > This can be extended to any static number of hops... but is it > possible to be done for a dynamic (unknown) number? > > ciao > svil > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---
