Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Storing a graph in a database

by roboticus (Chancellor)
on Aug 10, 2007 at 12:02 UTC ( [id://631772]=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    create table nodes (
        node_id int primary key,
        name varchar(32)
        -- other node info goes here
    )
    
  2. or download this
    create table edges (
        from_node_id int not null references nodes(node_id),
    ...
        description varchar(32)
        -- other edge info goes here
    )
    
  3. or download this
    -- Allowed states for "Daily Work Task"
    insert graph_nodes values (1, 'Wait/Idle')
    ...
    insert graph_edges values (5, 2, 'Fault resolved normally')
    insert graph_edges values (1, 6, 'System halted')
    insert graph_edges values (2, 6, 'System halted')
    
  4. or download this
    -- Where can I go from node 5?
    select  FR.node_id, '-->', TO.node_id, 'When: ' + E.description
    ...
    join    nodes FR on FR.node_id=E.from_node_id
    join    nodes TO on TO.node_id=E.to_node_id
    where   E.from_node_id = 5
    
  5. or download this
    node_id     node_id
    ------- --- ------- ----------------------------------
          5 -->       2 When: Fault resolved normally
          5 -->       6 When: Manual intervention required
    

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://631772]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (8)
As of 2024-04-16 07:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found