Robert Citek wrote: > Hello all, > > Does anyone have any recommendations for books or other resources that > deal with working with graphs (i.e. vertexes and edges) using sql? > > For example, if I could store a graph in a sqlite database, I'd like > to query the database to know if the graph contains a Eulerian > path[1]. > > [1] http://en.wikipedia.org/wiki/Eulerian_path I don't think that SQL is the best language for working with graphs, but:
CREATE TABLE Graph ( NodeFrom INTEGER, NodeTo INTEGER ); -- Seven Bridges of Königsberg BEGIN; INSERT INTO Graph VALUES (1, 2); INSERT INTO Graph VALUES (1, 2); INSERT INTO Graph VALUES (1, 3); INSERT INTO Graph VALUES (2, 3); INSERT INTO Graph VALUES (2, 4); INSERT INTO Graph VALUES (2, 4); INSERT INTO Graph VALUES (3, 4); COMMIT; CREATE TABLE Degrees AS SELECT NodeFrom AS Node, COUNT(*) AS Degree FROM (SELECT NodeFrom, NodeTo From Graph UNION ALL SELECT NodeTo, NodeFrom FROM Graph) GROUP BY NodeFrom; -- Find the number of odd nodes -- If 0, there is an Eulerian circuit/tour -- If 0 or 2, there is an Eulerian path/walk SELECT SUM(Degree & 1) FROM Degrees; _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users