Introduction
Apache AGE(AGE) is a PostgreSQL extension that enables hybrid queries using PostgreSQL. It boasts of a SET
clause which is used in adding labels on properties of already created vertices and edges. In this blog post, I am going to explain how these are done with examples.
Prerequisites.
I presume you have installed or have knowledge of the following.
- Postgres installed from source code.
- Apache AGE installed from source code.
- Basic knowledge of graph terminologies. If otherwise, the hyperlinks in each one will point you where to install them.
Supposing you have a graph named food
, with the following Vertices.
Details on how this graph was created can be seen in this blog post.
- The
SET
clause can be used to add a new property on a vertex, by executing the query below.
SELECT * FROM cypher('food', $$ MATCH (v:Recipes) SET v.meat = 'beef' RETURN v
$$) as (v agtype);
This query will add a new property called meat
to the vertex Recipes
- It can also be used to delete a property by setting its value to null.
SELECT * FROM cypher('food', $$
MATCH (v:Recipes)
SET v.meat = null RETURN v
$$) as (v agtype);
In the image above, the MATCH
clause was used to select the vertex Recipes
and its property meat
was removed by equating its value to null.
- It can be used to add multiple properties to a vertex at the same time, as can be seen in the image below.
SELECT *
FROM cypher('food', $$
MATCH (v:Recipes {name: 'Spaghetti'})
SET v.meat = 'beef',v.spice ="maggi" RETURN v
$$) as (v agtype);
Conclusion
The AGE SET
clause is very useful as it helps greatly in manipulating existing vertices.
Top comments (0)