Chidera Stella Onumajuru
Posted on June 30, 2023
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
MATCH
clause, with its contents stored in a variable and then the obtained variable will be deleted using theDELETE
clause, 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 DELETE
will 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
DELETE
clause 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
DELETE
the 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.
💖 💪 🙅 🚩
Chidera Stella Onumajuru
Posted on June 30, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
apacheage A Guide to PostgreSQL Extensions: Unlocking the Power of pgcrypto, pg_partman, and pg_stat_statements
October 1, 2023