Skip to content

Commit 578cc2a

Browse files
explain subqueries
1 parent 555416f commit 578cc2a

File tree

1 file changed

+31
-7
lines changed

1 file changed

+31
-7
lines changed

modules/ROOT/pages/clauses/with.adoc

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ 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#linear-query-composition[Enable linear composition of multiple queries]
1615

1716
[[example-graph]]
1817
== Example graph
@@ -164,6 +163,36 @@ RETURN s.name AS company,
164163
3+d|Rows: 5
165164
|===
166165

166+
`WITH` cannot de-scope variables imported to a xref:subqueries/call-subquery.adoc[`CALL` subquery], because variables imported to a subquery are considered global to its inner scope.
167+
More specifically, a variable imported into a `CALL` subquery will be available to subsequent clauses even if a preceding `WITH` clause does not reference it.
168+
169+
In the below example, the `x` variable is imported to the inside scope of a `CALL` subquery, and is successfully referenced by the `RETURN` clause even though the preceding `WITH` neglects to list it.
170+
171+
.Variables cannot be de-scoped in the inner scope of a subquery
172+
[source, cypher]
173+
----
174+
WITH 11 AS x
175+
CALL (x) {
176+
UNWIND [2, 3] AS y
177+
WITH y
178+
RETURN x*y AS a
179+
}
180+
RETURN x, a
181+
----
182+
183+
.Result
184+
[role="queryresult",options="header,footer",cols="2*<m"]
185+
|===
186+
| x | a
187+
188+
| 11 | 22
189+
| 11 | 33
190+
191+
2+d|Rows: 2
192+
|===
193+
194+
For more information, see xref:subqueries/call-subquery.adoc#import-variables[`CALL` subqueries -> Import variables].
195+
167196
[[bind-values-to-variables]]
168197
== Bind values to variables
169198

@@ -303,7 +332,7 @@ ORDER BY discountRates
303332
== Explicitly project values
304333

305334
`WITH ALL` can be used to explicitly project all values bound to a variable.
306-
This functionality was introduced as part of Cypher's xref:appendix/gql-conformance/index.adoc[], and using it is functionally the same as using simple `WITH`.
335+
Using it is functionally the same as using simple `WITH`.
307336

308337
.Explicit result projection using `WITH ALL`
309338
[source, cypher]
@@ -504,8 +533,3 @@ RETURN s.name AS supplier,
504533
[NOTE]
505534
The `FILTER` clause can be used as a more concise alternative to `WITH * WHERE <predicate>` constructs.
506535
For more information, see xref:clauses/filter.adoc#filter-with-where[`FILTER` as a substitute for `WITH * WHERE`].
507-
508-
[[linear-query-composition]]
509-
== Linear composition of multiple queries
510-
511-

0 commit comments

Comments
 (0)