Introduction
Apache AGE(AGE) is a PostgreSQL extension that enables hybrid queries using PostgreSQL. The AGE DELETE clause is used to delete Vertices and edges.
Prerequisites
Before following this tutorial, make sure you have:
- Installed PostgreSQL from source code. Here's a guide on installing PostgreSQL.
 - Installed and set up AGE from source code. Here's a guide on installing AGE.
 - Basic knowledge of Vertices and Edges in graph databases. Here's a beginner's guide to get you started.
 
The graph that is being queried in this tutorial has been created in a previous tutorial here and its contents it as follows.
- To delete a vertex, it has to be selected using the 
MATCHclause, with its contents stored in a variable and then the obtained variable will be deleted using theDELETEclause, here is a sample query below. 
SELECT * FROM cypher('food', $$ MATCH (v:Recipes) DELETE v $$) as (v agtype);
- Deleting this vertex made us encounter an error, this error occurred because the Vertex specified above have an edge, using 
DETACH DELETEwill get the two deleted as can be seen below. 
SELECT * FROM cypher('food', $$ MATCH (v:Recipes) DETACH DELETE v RETURN v $$) as (v agtype);
- The 
DELETEclause can be used to delete an edge, as can be seen in the query below. 
SELECT * FROM cypher('food', $$ MATCH (n:food_blog {name: 'Tasty Delight'})-[r:HAS_CONTENT]->(m:Meal_planning) DELETE r RETURN r $$) as (v agtype);
- Now we can  
DELETEthe remaining vertex with the code below. 
SELECT * FROM cypher('food', $$ MATCH (x:Meal_planning) DELETE v,x RETURN x $$) as (v x agtype);
Apache AGE DELETE clause helps in removing a vertex or an edge from a graph. Understanding its operation will help one to manipulate a graph better.
              





    
Top comments (0)