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;

To create a complete graph:

INSERT INTO edges
SELECT v1.vertex, v2.vertex
FROM vertexes v1 JOIN vertexes v2
WHERE v2.vertex > v1.vertex

To generate the irreflexive symmetric relation on vertexes:

CREATE VIEW isr AS
SELECT v1.vertex, v2.vertex
FROM vertexes v1 JOIN vertexes v2
WHERE v2.vertex != v1.vertex

So, there seem to be ways of working with graphs within sql.  I was
just curious to know if there were texts that cover this subject.  Joe
Celko's books seem like one source.  Are there others?

As for SQL not being the best for working with graphs, I'm ok with
that as I can use sqlite3 for storing and retrieving the graph data as
well as some of the more simpler manipulations, and then use some
other language for more sophisticated manipulations.

Regards,
- Robert
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to