> 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
ahha. thanks. So this is to look/represent/store different part of the thing; in my case i need to store and query the transitive closure (all possible paths) of the graph - and keep the node/edges elsewhere (which is graph's primary description). > 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. yeah, it queries/stores some precomputed thing and not the original tree/graph decription itself. Hence the overhead of pre-computing at every change. in my case i may not realy need SQL for this as the graph is relatively small, so i can load all of it, compute somehow and store just the query-results for future direct reference/query. Which is more or less the same thing as above, just going one step further. > 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 sqlalchemy@googlegroups.com 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 -~----------~----~----~----~------~----~------~--~---