UltipaDocs
Try Playground
  • Introduction
  • GQL vs Other Languages
    • Overview
    • Node and Edge Patterns
    • Path Patterns
    • Quantified Paths
    • Shortest Paths
    • Graph Patterns
    • Overview
    • Closed Graph
    • Open Graph
    • Graph Sharding and Storage
    • Constraints
    • Unique Identifiers
    • INSERT
    • INSERT OVERWRITE
    • UPSERT
    • 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
    • Scalar Functions
    • Path Functions
    • Aggregate Functions
    • Mathematical Functions
    • Trigonometric Functions
    • String Functions
    • List Functions
    • Datetime Functions
    • Spatial Functions
    • Type Conversion Functions
    • Table Functions
    • AI & Vector Functions
    • Database Functions
  • Operators
  • Predicates
  • Expressions
    • 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.

In the case of DELETE or NODETACH DELETE, the deletion of node B will fail, which can be useful as a security measure to prevent unintended deletions. If not explicitly specified, NODETACH is applied.

Example Graph

CREATE GRAPH myGraph {
  NODE User ({name STRING}),
  NODE Club (),
  EDGE Follows ()-[]->(),
  EDGE Joins ()-[]->()
}

Deleting Isolated Nodes

To delete the isolated nodes purplechalk and lionbower:

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

The [NODETACH] DELETE statement can only delete isolated nodes, if any node specified has connected edges, an error will be thrown, and no nodes will be deleted.

Deleting Any Nodes

To delete the node rowlock along with its connected edges:

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

Deleting All Nodes and Edges

To delete all nodes along with all edges:

GQL
MATCH (n)
DETACH DELETE n

Deleting Edges

To 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.

To delete any two edges:

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