From 4abeb528628a63d2e0c883fddb72e43083f2829b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20Pryce-=C3=85klundh?= <112686610+JPryce-Aklundh@users.noreply.github.com> Date: Fri, 16 May 2025 05:43:40 +0200 Subject: [PATCH 1/3] initial --- .../pages/clauses/clause-composition.adoc | 21 +++++++++++++++++-- modules/ROOT/pages/clauses/with.adoc | 3 +++ ...ions-additions-removals-compatibility.adoc | 1 + 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/modules/ROOT/pages/clauses/clause-composition.adoc b/modules/ROOT/pages/clauses/clause-composition.adoc index d3e1949d0..64b5d26e6 100644 --- a/modules/ROOT/pages/clauses/clause-composition.adoc +++ b/modules/ROOT/pages/clauses/clause-composition.adoc @@ -129,9 +129,26 @@ 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 the a write clause (xref:clauses/set.adoc[`SET`]) is 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 ====== diff --git a/modules/ROOT/pages/clauses/with.adoc b/modules/ROOT/pages/clauses/with.adoc index ebc2460dc..fb2b642b4 100644 --- a/modules/ROOT/pages/clauses/with.adoc +++ b/modules/ROOT/pages/clauses/with.adoc @@ -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: diff --git a/modules/ROOT/pages/deprecations-additions-removals-compatibility.adoc b/modules/ROOT/pages/deprecations-additions-removals-compatibility.adoc index 6b176a145..cf6212d44 100644 --- a/modules/ROOT/pages/deprecations-additions-removals-compatibility.adoc +++ b/modules/ROOT/pages/deprecations-additions-removals-compatibility.adoc @@ -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 -> Red-write queries] a| label:functionality[] From 0a605d752be276f7186db4245b861a3f81e6359e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20Pryce-=C3=85klundh?= <112686610+JPryce-Aklundh@users.noreply.github.com> Date: Fri, 16 May 2025 05:53:27 +0200 Subject: [PATCH 2/3] fixes and grammar --- modules/ROOT/pages/clauses/clause-composition.adoc | 2 +- .../pages/deprecations-additions-removals-compatibility.adoc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/ROOT/pages/clauses/clause-composition.adoc b/modules/ROOT/pages/clauses/clause-composition.adoc index 64b5d26e6..d3d64c964 100644 --- a/modules/ROOT/pages/clauses/clause-composition.adoc +++ b/modules/ROOT/pages/clauses/clause-composition.adoc @@ -133,7 +133,7 @@ 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 the a write clause (xref:clauses/set.adoc[`SET`]) is 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]. +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 diff --git a/modules/ROOT/pages/deprecations-additions-removals-compatibility.adoc b/modules/ROOT/pages/deprecations-additions-removals-compatibility.adoc index cf6212d44..d5e8e7ddb 100644 --- a/modules/ROOT/pages/deprecations-additions-removals-compatibility.adoc +++ b/modules/ROOT/pages/deprecations-additions-removals-compatibility.adoc @@ -200,7 +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 -> Red-write queries] +For more information, see xref:clauses/clause-composition.adoc#cypher-clause-composition-rw-queries[Clause composition -> Read-write queries]. a| label:functionality[] From bf79dde537023fa31f433efa553c9a98e50291a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20Pryce-=C3=85klundh?= <112686610+JPryce-Aklundh@users.noreply.github.com> Date: Fri, 16 May 2025 05:54:13 +0200 Subject: [PATCH 3/3] return --- modules/ROOT/pages/clauses/clause-composition.adoc | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/modules/ROOT/pages/clauses/clause-composition.adoc b/modules/ROOT/pages/clauses/clause-composition.adoc index d3d64c964..012cdad48 100644 --- a/modules/ROOT/pages/clauses/clause-composition.adoc +++ b/modules/ROOT/pages/clauses/clause-composition.adoc @@ -143,11 +143,10 @@ 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 +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