UltipaDocs
Products
Solutions
Resources
Company
Start Free Trial
UltipaDocs
Start Free Trial
  • Introduction
  • GQL vs Other Languages
    • Overview
    • Node and Edge Patterns
    • Path Patterns
    • Quantified Paths
    • Questioned Paths
    • Shortest Paths
    • Graph Patterns
    • Overview
    • Open Graph
    • Closed Graph
    • Constraints
    • Unique Identifiers
    • INSERT
    • INSERT OVERWRITE
    • SET
    • REMOVE
    • DELETE
    • Query Composition
    • Result Table and Visualization
    • MATCH
    • OPTIONAL MATCH
    • FILTER
    • LET
    • FOR
    • ORDER BY
    • LIMIT
    • SKIP
    • CALL
    • RETURN
    • Composite Query
    • NEXT
    • All Functions
    • Element Functions
    • Path Functions
    • Aggregate Functions
    • Mathematical Functions
    • Trigonometric Functions
    • String Functions
    • List Functions
    • Datetime Functions
    • Spatial Functions
    • Null Functions
    • Utility Functions
    • Type Conversion Functions
    • Table Functions
    • AI & Vector Functions
    • Database Functions
  • Operators
  • Predicates
    • CASE
    • LET Value Expression
    • Value Query Expression
    • List Comprehension
    • Index
    • Full-text Index
    • Vector Index
  • Transactions
  • Triggers
  • Query Management
  • Backup and Restore
    • Variables
    • Values and Types
    • Comments
    • Reserved Words
    • Syntactic Notation
  • GQL Conformance
  1. Docs
  2. /
  3. ISO GQL
  4. /
  5. Data Modification

DELETE

Overview

The DELETE statement allows you to delete nodes and edges from a graph. These nodes or edges must first be retrieved using the MATCH statement.

An edge cannot exist when any of its endpoints is removed from the graph. Therefore, by default GQL does not allow to delete a node while it still has edges connected to it. You can bypass this restriction by explicitly using the keyword DETACH to enable the deletion of nodes along with their connected edges. For example, when node B is deleted by DETACH DELETE, edges 1, 2 and 4 will also be deleted.

Without DETACH, the deletion of node B will fail, which can be useful as a security measure to prevent unintended deletions.

Example Graph

GQL
INSERT (rowlock:User {_id: "U01", name: "rowlock"}),
       (brainy:User {_id: "U02", name: "Brainy"}),
       (mochaeach:User {_id: "U03", name: "mochaeach"}),
       (purplechalk:User {_id: "U04", name: "purplechalk"}),
       (lionbower:User {_id: "U05", name: "lionbower"}),
       (c:Club {_id: "C01"}),
       (rowlock)-[:Follows]->(brainy),
       (mochaeach)-[:Follows]->(brainy),
       (brainy)-[:Joins]->(c)

Deleting Isolated Nodes

Delete the isolated nodes purplechalk and lionbower:

GQL
MATCH (n:User) WHERE n.name IN ["purplechalk", "lionbower"] 
DELETE n

The DELETE statement (without DETACH) can only delete isolated nodes. If any node specified has connected edges, an error will be thrown.

Deleting Any Nodes

Delete the node rowlock along with its connected edges:

GQL
MATCH (n:User {name: 'rowlock'})
DETACH DELETE n

Deleting All Nodes and Edges

Delete all nodes along with all edges:

GQL
MATCH (n)
DETACH DELETE n

Deleting Edges

Delete all Follows edges:

GQL
MATCH ()-[e:Follows]->()
DELETE e

Limiting the Amount to Delete

To limit the number of nodes or edges to delete, apply the LIMIT statement after MATCH to keep only the first N records before passing the variable to the DELETE statement.

Delete any two edges:

GQL
MATCH ()-[e]->() LIMIT 2
DELETE e