You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: modules/ROOT/pages/clauses/clause-composition.adoc
+117-3Lines changed: 117 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -130,13 +130,31 @@ The most important aspect of read-write queries is that the state of the graph a
130
130
131
131
[IMPORTANT]
132
132
====
133
-
A clause can never observe writes made by a later clause.
133
+
A clause can never observe writes made by a later clause, and will observe all writes done by the previous clauses.
134
134
====
135
135
136
+
As of Cypher 25, read and write clauses can be combined in any order.
137
+
That is, a write clause followed by a read clause no longer requires a separating xref:clauses/with.adoc[`WITH`] clause in order for the read clause to observe the changes made by a preceding write clause.
138
+
For example, the following query, in which the changes made by a write clause (xref:clauses/set.adoc[`SET`]) are observed by a subsequent `MATCH` clause without an intermediate `WITH` clause, is valid using Cypher 25 but not link:https://neo4j.com/docs/cypher-manual/current/clauses/with/#combine-write-and-read-clauses[Cypher 5].
139
+
140
+
141
+
.Combine write and read clauses without a separating `WITH` clause
142
+
[source, cypher]
143
+
----
144
+
MATCH (j:Person {name: 'John'})-[:FRIEND]->(f)
145
+
SET f.degreesFromJohn = 1
146
+
MATCH (f)-[:FRIEND]->(f2)
147
+
SET f2.degreesFromJohn = f.degreesFromJohn + 1
148
+
RETURN f.name AS friendName,
149
+
f.degreesFromJohn AS friendDegree,
150
+
f2.name AS friendOfFriendName,
151
+
f2.degreesFromJohn AS friendOfFriendDegree
152
+
----
153
+
136
154
.Table of intermediate results and state of the graph between read and write clauses
137
155
======
138
156
139
-
Using the same example graph as above, this example shows the table of intermediate results and the state of the graph after each clause for the following query:
157
+
Using the same example graph as above, this example shows the table of intermediate results and the state of the graph after each clause for a query with a read clause before a write clause:
140
158
141
159
[source,cypher, indent=0]
142
160
----
@@ -147,7 +165,7 @@ The query finds all nodes where the `name` property starts with "J"
147
165
and for each such node it creates another node with the `name` property set to "Jay-jay".
148
166
149
167
150
-
.+The table of intermediate results and the state of the graph after each clause+
168
+
.Read-write: The table of intermediate results and the state of the graph after each clause+
@@ -294,6 +312,102 @@ the graph made by the `CREATE`.
294
312
295
313
======
296
314
315
+
.Table of intermediate results and state of the graph between write and read clauses
316
+
======
317
+
On an empty graph, this example shows the table of intermediate results and the state of the graph after each clause for a query with a write clause before a read clause:
318
+
319
+
[source,cypher, indent=0]
320
+
----
321
+
UNWIND ["Max", "Lune"] AS dogName
322
+
CREATE (n:Dog {name: dogName})
323
+
WITH n
324
+
MATCH (d:Dog)
325
+
RETURN COUNT(*)
326
+
----
327
+
This query creates two `Dog` nodes and returns the value `4`.
328
+
329
+
.+Write-read: The table of intermediate results and the state of the graph after each clause+
0 commit comments