如何避免 AgensGraph 上的重复顶点节点?

How to avoid duplicate vertex node on AgensGraph?

我想在两个顶点上创建边。

agens=# create (:v1{id:1}), (:v1{id:2});
GRAPH WRITE (INSERT VERTEX 2, INSERT EDGE 0)
agens=# create (:v1{id:1})-[:e1{id:3}]->(:v1{id:2});
GRAPH WRITE (INSERT VERTEX 2, INSERT EDGE 1)
agens=# match (n:v1) return n;
        n         
------------------
 v1[3.1]{"id": 1}
 v1[3.2]{"id": 2}
 v1[3.3]{"id": 1}
 v1[3.4]{"id": 2}
(4 rows)

但是,上面有重复的顶点。

如何避免 AgensGraph 上的重复顶点节点?

首先,使用匹配找到顶点

之后,使用找到的顶点添加边。

agens=# create (:v1{id:1}), (:v1{id:2});
GRAPH WRITE (INSERT VERTEX 2, INSERT EDGE 0)
agens=# match (n1:v1{id:1}), (n2:v1{id:2}) create (n1)-[:e1{id:3}]->(n2);
GRAPH WRITE (INSERT VERTEX 0, INSERT EDGE 1)
agens=# match (n:v1) return n;
        n         
------------------
 v1[3.1]{"id": 1}
 v1[3.2]{"id": 2}
(2 rows)