Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions modules/ROOT/pages/clauses/clause-composition.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,25 @@ In a Cypher query, read and write clauses can take turns.
The most important aspect of read-write queries is that the state of the graph also changes between clauses.

[IMPORTANT]
====
A clause can never observe writes made by a later clause.
====

As of Cypher 25, read and write clauses can be combined in any order.
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.
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].


.Combine write and read clauses without a separating `WITH` clause
[source, cypher]
----
MATCH (j:Person {name: 'John'})-[:FRIEND]->(f)
SET f.degreesFromJohn = 1
MATCH (f)-[:FRIEND]->(f2)
SET f2.degreesFromJohn = f.degreesFromJohn + 1
RETURN f.name AS friendName,
f.degreesFromJohn AS friendDegree,
f2.name AS friendOfFriendName,
f2.degreesFromJohn AS friendOfFriendDegree
----

.Table of intermediate results and state of the graph between read and write clauses
======
Expand Down
3 changes: 3 additions & 0 deletions modules/ROOT/pages/clauses/with.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ The `WITH` clause serves multiple purposes in Cypher:
* xref:clauses/with.adoc#ordering-pagination[Order and paginate results]
* xref:clauses/with.adoc#filter-results[Filter results]

[IMPORTANT]
As of Cypher 25, `WITH` is no longer required as a separator between a write and a read clause.

[[example-graph]]
== Example graph
A graph with the following schema is used for the examples below:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ RETURN count(p) AS count
----

| Queries no longer require xref:clauses/with.adoc[`WITH`] to transition between reading and writing operations.
For more information, see xref:clauses/clause-composition.adoc#cypher-clause-composition-rw-queries[Clause composition -> Read-write queries].

a|
label:functionality[]
Expand Down