DEV Community

Muhammad Muneeb Ur Rehman
Muhammad Muneeb Ur Rehman

Posted on

Create Edge in Apache AGE

In Apache AGE, data is stored in edges and vertices. In this blog, I will tell you how you can create edge and how you can store data in it.
Firstly, in edge we have edge name, formally we call it label.
Secondly, we can also store data in the edge. The data is stored in key value pair.


Simple Edge General Form

SELECT *
FROM cypher('graph_name', $$
MATCH (a:VertexLabelName), (b:VertexLabelName)
WHERE a.PropertyName = 'AnyThing' AND b.PropertyName = 'AnyThing'
CREATE (a)-[e:RelationName]->(b)
RETURN e
$$) as (e agtype);

Explanation:
We selected the Graph, SELECT * FROM cypher('graph_name', $$ which we are going to use. We matched the labels of the vertices on which we want to create the edge using MATCH (a:VertexLabelName), (b:VertexLabelName). Afterwards, we apply a condition on the vertices using WHERE a.PropertyName = 'AnyThing' AND b.PropertyName = 'AnyThing'. Now we have got the two desired vertices between which we want to create an edge.
We can create an edge using CREATE (a)-[e:RelationName]->(b). We can get the newly created edge information using RETURN e
$$) as (e agtype);


Edge with Properties General Form

SELECT *
FROM cypher('graph_name', $$
MATCH (a:VertexLabelName), (b:VertexLabelName)
WHERE a.PropertyName = 'AnyThing' AND b.PropertyName = 'AnyThing'
CREATE (a)-[e:RelationName{edgePropertyName:'Anything', ...}]->(b)
RETURN e
$$) as (e agtype);

Explanation:
We selected the Graph, SELECT * FROM cypher('graph_name', $$ which we are going to use. We matched the labels of the vertices on which we want to create the edge using MATCH (a:VertexLabelName), (b:VertexLabelName). Afterwards, we apply a condition on the vertices using WHERE a.PropertyName = 'AnyThing' AND b.PropertyName = 'AnyThing'. Now we have got the two desired vertices between which we want to create an edge.
We can create an edge along with its properties using CREATE (a)-[e:RelationName{edgePropertyName:'Anything', ...}]->(b). We can also define more properties here using the key : value pair, {edgePropertyName:'Anything', ...}. ... means edgePropertyName2:'Anything2', edgePropertyName3:'Anything3', and so on. We can get the newly created edge information using RETURN e
$$) as (e agtype);


For more details visit: https://age.apache.org/overview/

AGE Github Link: https://github.com/apache/age

AGE Viewer Github Link: https://github.com/apache/age-viewer

Top comments (0)