YMatrix
Quick Start
Connecting
Benchmarks
Deployment
Data Usage
Manage Clusters
Upgrade
Global Maintenance
Expansion
Monitoring
Security
Best Practice
Technical Principles
Data Type
Storage Engine
Execution Engine
Streaming Engine(Domino)
MARS3 Index
Extension
Advanced Features
Advanced Query
Federal Query
Grafana
Backup and Restore
Disaster Recovery
Graph Database
Introduction
Clauses
Functions
Advanced
Guide
Performance Tuning
Troubleshooting
Tools
Configuration Parameters
SQL Reference
The DELETE clause removes graph elements — vertices, edges, or paths.
Note!
Restrictions onDELETEin YMatrix AGE:
- You cannot
SETproperties on a variable afterDELETEing it.MATCH (n) DELETE n SET n.lol = 'ftw' RETURN n -- ERROR: cannot SET property on deleted variable n- You cannot
CREATEan edge referencing a variable that wasDELETEd in the same query.MATCH (a)-[e:KNOWS]->(b) DELETE e CREATE (a)-[:KNOWS {reason: 'new'}]->(b) -- ERROR: AssignTransactionId() called by Segment Reader processRecommendation: Split
DELETEand subsequent write operations into separate Cypher statements.
A DELETE clause not followed by any other clause is called a terminal clause. When a Cypher query ends with a terminal clause, the cypher() function returns no rows. However, the function call still requires a column definition list — for example, AS (v agtype). When the query ends with a terminal clause, you may define any dummy column name; it will not contain data.
To remove properties, see REMOVE.
You cannot delete a vertex without also deleting all edges for which it serves as either start or end vertex. Either explicitly delete those edges first, or use DETACH DELETE.
To delete a vertex, use the DELETE clause.
SELECT *
FROM cypher('graph_name', $$
MATCH (v:Useless)
DELETE v
$$) AS (v agtype);
This deletes vertices labeled Useless that have no incident edges. The query returns no data.
| v |
|---|
| (0 rows) |
Use MATCH to bind vertices, then apply DETACH DELETE to first remove all incident edges and then delete the vertices themselves.
SELECT *
FROM cypher('graph_name', $$
MATCH (v:Useless)
DETACH DELETE v
$$) AS (v agtype);
This query returns no data.
| v |
|---|
| (0 rows) |
To delete an edge, first MATCH it, then include its bound variable in the DELETE clause.
SELECT *
FROM cypher('graph_name', $$
MATCH (n {name: 'Andres'})-[r:KNOWS]->()
DELETE r
$$) AS (v agtype);
This query returns no data.
| v |
|---|
| (0 rows) |
You may return a deleted vertex using RETURN.
SELECT *
FROM cypher('graph_name', $$
MATCH (n {name: 'A'})
DELETE n
RETURN n
$$) AS (a agtype);
| v |
|---|
{"id": 281474976710659, "label": "", "properties": {"name": "A"}}::vertex |
| (1 row) |