Robert Citek wrote:
> On Sun, Jan 10, 2010 at 8:06 PM, Dan Bishop <danbisho...@gmail.com> wrote:
>> Robert Citek wrote:
>>> Does anyone have any recommendations for books or other resources that
>>> deal with working with graphs (i.e. vertexes and edges) using sql?
>>>
>> I don't think that SQL is the best language for working with graphs, but:
>>
>> CREATE TABLE Graph (
>> NodeFrom INTEGER,
>> NodeTo INTEGER
>> );
> 
> Yes, the Koenigsberg bridge problem is just one example of what I am
> referring to.
> 
> I was working on creating a more general model initially with just two
> tables: one for vertexes and one for edges, which is a pairing of
> vertexes.  For example:
> 
> create table vertexes ( vertex integer ) ;
> create table edges ( v1 integer, v2 integer ) ;
> BEGIN;
> INSERT INTO vertexes VALUES (1);
> INSERT INTO vertexes VALUES (2);
> INSERT INTO vertexes VALUES (3);
> INSERT INTO vertexes VALUES (4);
> COMMIT;

I store all the data for my waterways route planner in SQLite, but I 
load it into memory for running Dijkstra's algorithm on it to find the 
shortest (when weighted) paths.   It's at canalplan.eu if anyone wants a 
play.

One problem you rapidly run into when storing graphs in SQL, in my 
limited and non-expert experience, is that - as in this example - you 
end up with edge records each of which refers to two vertices.  My 
database maintenance and update code is riddled with:

SELECT ... FROM link WHERE place1=x AND place2=y OR place1=y AND place2=x;

and similar.  Apart from imposing a condition (such as always having v1 
< v2 in the example code) is there any sensible way round this?
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to