DEV Community

Chidera Stella Onumajuru
Chidera Stella Onumajuru

Posted on

Apache AGE SET Clause.

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.

  1. Postgres installed from source code.
  2. Apache AGE installed from source code.
  3. 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.

Image showing all vertices created in a graph known as food

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);
Enter fullscreen mode Exit fullscreen mode

This query will add a new property called meat to the vertex Recipes

Image description

  • 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);
Enter fullscreen mode Exit fullscreen mode

Image description
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);
Enter fullscreen mode Exit fullscreen mode

Image description

Conclusion
The AGE SET clause is very useful as it helps greatly in manipulating existing vertices.

Top comments (0)