Skip to content

Commit 6083e63

Browse files
Cypher 5 changes
1 parent 26db86f commit 6083e63

File tree

1 file changed

+33
-35
lines changed

1 file changed

+33
-35
lines changed

modules/ROOT/pages/clauses/with.adoc

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ The `WITH` clause serves multiple purposes in Cypher:
1212
* xref:clauses/with.adoc#remove-duplicate-values[Remove duplicate values]
1313
* xref:clauses/with.adoc#ordering-and-pagination[Order and paginate results]
1414
* xref:clauses/with.adoc#filter-results[Filter results]
15+
* xref:clauses/with.adoc#combine-write-and-read-clauses[Combine write and read clauses]
1516

1617
[[example-graph]]
1718
== Example graph
@@ -61,7 +62,6 @@ CREATE (techCorp:Supplier {name: 'TechCorp', email: '[email protected]'}),
6162
(foodies)-[:SUPPLIES]->(chocolate),
6263
(foodies)-[:SUPPLIES]->(coffee)
6364
----
64-
// end::clauses_with_variables[]
6565

6666
[[create-new-variables]]
6767
== Create new variables
@@ -95,7 +95,6 @@ MATCH (c:Customer)-[:BUYS]->(:Product {name: 'Chocolate'})
9595
WITH c AS customer
9696
RETURN customer.firstName AS chocolateCustomer
9797
----
98-
// end::clauses_with_wildcard[]
9998

10099
.Result
101100
[role="queryresult",options="header,footer",cols="1*<m"]
@@ -195,7 +194,7 @@ For more information, see xref:subqueries/call-subquery.adoc#import-variables[`C
195194
== Bind values to variables
196195

197196
`WITH` can be used to assign the values of expressions to variables.
198-
In the below query, the value of the xref:expressions/string-operators.adoc[`STRING` concatenation] expression is bound to a new variable `customerFullName`, and the value from the expression `chocolate.price * (1 - customer.discount)` is bound to `chocolateNetPrice`, both of which are then available in the `RETURN` clause.
197+
In the below query, the value of the `STRING` concatenation expression is bound to a new variable `customerFullName`, and the value from the expression `chocolate.price * (1 - customer.discount)` is bound to `chocolateNetPrice`, both of which are then available in the `RETURN` clause.
199198

200199
.Bind values to variables
201200
[source, cypher]
@@ -320,38 +319,6 @@ ORDER BY discountRates
320319
1+d|Rows: 5
321320
|===
322321

323-
[role=label--new-2025.05]
324-
[[with-all-results]]
325-
== Explicitly project values
326-
327-
`WITH ALL` can be used to explicitly project all values bound to a variable.
328-
Using it is functionally the same as using simple `WITH`.
329-
330-
.Explicit result projection using `WITH ALL`
331-
[source, cypher]
332-
----
333-
MATCH (c:Customer)
334-
WITH ALL c.discount AS discountRates
335-
RETURN discountRates
336-
ORDER BY discountRates
337-
----
338-
339-
.Result
340-
[role="queryresult",options="header,footer", cols="1*<m"]
341-
|===
342-
| discountRates
343-
344-
| 0.05
345-
| 0.1
346-
| 0.1
347-
| 0.1
348-
| 0.15
349-
| 0.2
350-
| 0.25
351-
352-
1+d|Rows: 7
353-
|===
354-
355322
[[ordering-pagination]]
356323
== Ordering and pagination
357324

@@ -526,3 +493,34 @@ RETURN s.name AS supplier,
526493
3+d|Rows: 1
527494
|===
528495

496+
[[combine-write-and-read-clauses]]
497+
== Combine write and read clauses
498+
499+
If a write clause is followed by a read clause, `WITH` must be used as a separator between the two.
500+
501+
.`WITH` used as a separator between a write clause and a read clause
502+
[source, cypher]
503+
----
504+
MATCH (yusuf:Customer {firstName: 'Yusuf'}),
505+
(coffee:Product {name: 'Coffee'}),
506+
(headphones:Product {name: 'Headphones'})
507+
CREATE (yusuf)-[:BUYS {date: date('2025-04-15')}]->(coffee),
508+
(yusuf)-[:BUYS {date: date('2025-04-15')}]->(headphones)
509+
WITH yusuf
510+
MATCH (yusuf)-[r:BUYS]->(p:Product)
511+
RETURN collect(p.name) AS yusufPurchases,
512+
r.date AS date
513+
ORDER BY date DESC
514+
----
515+
516+
[role="queryresult",options="header,footer", cols="2*<m"]
517+
|===
518+
519+
| yusufPurchases | date
520+
521+
| ["Coffee", "Headphones"] | 2025-04-15
522+
| ["Laptop"] | 2025-01-02
523+
| ["Chocolate"] | 2024-12-24
524+
525+
2+d|Rows: 3
526+
|===

0 commit comments

Comments
 (0)