agens-graph

How to create star shaped graph on AgensGraph?


I want to create star shaped graph using single "CREATE" statement of CYPHER.

How to create star shaped graph on AgensGraph?


Solution

  • Use variable on first cypher pattern, and reuse variable on following cypher patterns.

    agens=# create (n:v{id:1})-[:e]->(:v{id:2}), 
                   (n)-[:e]->(:v{id:3}), 
                   (n)-[:e]->(:v{id:4});
    
    GRAPH WRITE (INSERT VERTEX 4, INSERT EDGE 3)
    agens=# match p = (n:v{id:1})-[:e]->() return p;
                              p                          
    -----------------------------------------------------
     [v[3.1]{"id": 1},e[4.1][3.1,3.2]{},v[3.2]{"id": 2}]
     [v[3.1]{"id": 1},e[4.2][3.1,3.3]{},v[3.3]{"id": 3}]
     [v[3.1]{"id": 1},e[4.3][3.1,3.4]{},v[3.4]{"id": 4}]
    (3 rows)