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/queries/composed-queries/sequential-queries.adoc
+91-65Lines changed: 91 additions & 65 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -142,20 +142,17 @@ RETURN customer.firstName AS chocolateCustomer,
142
142
|===
143
143
====
144
144
145
-
146
-
147
145
[NOTE]
148
146
====
149
-
Expressions in a `RETURN` clause must be aliased with an `AS` or a `LET` when they are followed by a `NEXT` clause.
147
+
When followed by a `NEXT` clause, expressions in a `RETURN` clause must either be variables that have been introduced before or they must be aliased with `AS`.
150
148
====
151
149
152
-
// is an example necessary? not a fan of negative examples in general
153
-
154
150
155
151
== Interactions with `CALL` subqueries and `WITH`
156
152
157
153
You can use `NEXT` to rewrite queries containing `CALL` subqueries or a `WITH` clause.
Even though the `NEXT` query in <<call-subquery-rewrite>> has more lines, it is divided into three segments which are easy to read.
204
+
It also avoids the parentheses and indentation of the `CALL` subquery.
206
205
206
+
[[with-rewrite]]
207
207
.Rewriting a `WITH` query
208
208
====
209
209
[cols="1,1"]
@@ -246,80 +246,106 @@ RETURN d
246
246
|===
247
247
====
248
248
249
-
Variables which are local to a query and which are not explicitly returned are not accessible by its subsequent query in the context of `NEXT`.
250
-
This allows you to control variable scope similarly to what you can do with `WITH`, see xref:clauses/with.adoc#variable-scope[Control variables in scope].
249
+
250
+
Variables which are local to a query and which are not explicitly returned are not accessible by subsequent queries in the context of `NEXT`.
251
+
This allows you to control variable scope similarly to what you can do with `WITH`, see xref:clauses/with.adoc#variable-scope[Control variables in scope]: in <<with-rewrite>>, each occurrence of `WITH` is replaced by a `RETURN` and a `NEXT`, preserving the variable scope.
251
252
252
253
[NOTE]
253
254
====
254
255
`NEXT` cannot be used inside a `CALL` subquery that uses the (deprecated) xref:subqueries/call-subquery.adoc#importing-with[importing `WITH`] syntax.
255
256
====
256
257
257
-
== Interactions with conditional queries
258
258
259
-
// use example with the example data set instead
259
+
== Interactions with conditional queries
260
260
261
+
[[next-and-conditional]]
261
262
.`NEXT` in a conditional query
262
263
====
263
264
.Query
264
265
[source, cypher]
265
266
----
266
-
MATCH (n)
267
-
RETURN n
267
+
MATCH (c:Customer)-[:BUYS]->(:Product)<-[:SUPPLIES]-(s:Supplier)
268
+
RETURN c.firstName AS customer, s.name AS supplier
268
269
269
-
NEXT
270
+
NEXT
270
271
271
-
WHEN n.x > 2 THEN
272
-
RETURN "large number" AS msg
273
-
WHEN n.x > 1 THEN
274
-
RETURN "small number" AS msg
275
-
ELSE
276
-
RETURN "tiny number" AS msg
272
+
WHEN supplier = "TechCorp" THEN
273
+
RETURN customer, "Tech enjoyer" AS personality
274
+
WHEN supplier = "Foodies Inc." THEN
275
+
RETURN customer, "Tropical plant enjoyer" AS personality
276
+
277
+
NEXT
277
278
279
+
RETURN customer, collect(DISTINCT personality) AS personalities
280
+
281
+
NEXT
282
+
283
+
WHEN size(personalities) > 1 THEN
284
+
RETURN customer, "Enjoyer of tech and plants" AS personality
0 commit comments