DEV Community

Cover image for Understanding the Apache AGE DELETE Clause.
steila
steila

Posted on

3

Understanding the Apache AGE DELETE Clause.

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:

  1. Installed PostgreSQL from source code. Here's a guide on installing PostgreSQL.
  2. Installed and set up AGE from source code. Here's a guide on installing AGE.
  3. 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.

An image showing the vertices we are working with

An image showing the edges we are working with

  • 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 the DELETEclause, here is a sample query below.
SELECT * FROM cypher('food', $$ MATCH (v:Recipes) DELETE v $$) as (v agtype);
Enter fullscreen mode Exit fullscreen mode

An image showing the query result

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

An image showing the query result

  • 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);

Enter fullscreen mode Exit fullscreen mode

An image showing the query result

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

An image showing the query result
Conclusion

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.

API Trace View

How I Cut 22.3 Seconds Off an API Call with Sentry

Struggling with slow API calls? Dan Mindru walks through how he used Sentry's new Trace View feature to shave off 22.3 seconds from an API call.

Get a practical walkthrough of how to identify bottlenecks, split tasks into multiple parallel tasks, identify slow AI model calls, and more.

Read more →

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more