Skip to content

Commit 6b780b6

Browse files
Add ALL keyword to RETURN clause as part of GQL compliance (#1139)
Added ALL keyword for GQL compliance for RETURN, and for consistency to WITH --------- Co-authored-by: Jens Pryce-Åklundh <[email protected]>
1 parent 543f630 commit 6b780b6

File tree

4 files changed

+101
-2
lines changed

4 files changed

+101
-2
lines changed

modules/ROOT/pages/appendix/gql-conformance/supported-mandatory.adoc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,7 @@ The only way to guarantee row order in Neo4j is to use xref:clauses/order-by.ado
7373
| 14.11
7474
| <return statement>
7575
| xref:clauses/return.adoc[`RETURN`]
76-
| GQL defines the option to specify `RETURN ALL` (functionally equivalent to using `RETURN` on its own).
77-
This is currently not available in Cypher.
76+
|
7877

7978
| 15.4
8079
| <conditional statement>

modules/ROOT/pages/clauses/return.adoc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,3 +236,27 @@ The `Movie` node `'Man of Tai Chi'` is returned by the query, but only once (wit
236236
d|Rows: 1
237237
|===
238238

239+
[role=label--new-2025.05]
240+
[[return-all-results]]
241+
== RETURN ALL
242+
243+
Returning all results can also be accomplished by explicitly including `ALL` in the `RETURN`.
244+
The `RETURN ALL` keyword was introduced as part of Cypher's xref:appendix/gql-conformance/index.adoc[], and using it is functionally the same as using simple `RETURN`.
245+
246+
.Query
247+
[source, cypher]
248+
----
249+
MATCH (p:Person {name: 'Keanu Reeves'})-->(m)
250+
RETURN ALL m
251+
----
252+
253+
The same node is returned twice, as there are two relationships connecting to it from `'Keanu Reeves'`.
254+
255+
.Result
256+
[role="queryresult",options="header,footer",cols="1*<m"]
257+
|===
258+
| m
259+
| {"title":"Man of Tai Chi","released":2013}+
260+
| {"title":"Man of Tai Chi","released":2013}+
261+
d|Rows: 1
262+
|===

modules/ROOT/pages/clauses/with.adoc

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,3 +234,56 @@ As the limit is larger than the total number of remaining rows, all rows are ret
234234
| 6
235235
|Rows: 4
236236
|===
237+
238+
[[with-unique-results]]
239+
== Unique results
240+
241+
`DISTINCT` retrieves only unique rows for the columns that have been selected for projection.
242+
243+
.Query
244+
[source, cypher]
245+
----
246+
MATCH (n)-[:KNOWS]->(p)
247+
WITH DISTINCT p.name AS name
248+
RETURN name
249+
----
250+
251+
`'George'` is returned by the query, but only once (without the `DISTINCT` operator it would have been returned twice because there are two `KNOWS` relationships going to it):
252+
253+
.Result
254+
[role="queryresult",options="header,footer",cols="1*<m"]
255+
|===
256+
| name
257+
| "Bossman"
258+
| "George"
259+
| "Anders"
260+
d|Rows: 3
261+
|===
262+
263+
264+
[[with-all-results]]
265+
== WITH ALL
266+
267+
Projecting all results can also be accomplished by explicitly including `ALL` in the `WITH`.
268+
269+
.Query
270+
[source, cypher]
271+
----
272+
MATCH (n)-[:KNOWS]->(p)
273+
WITH ALL p.name AS name
274+
RETURN name
275+
----
276+
277+
The same name is returned twice, as there are two `KNOWS` relationships connecting to it.
278+
279+
.Result
280+
[role="queryresult",options="header,footer",cols="1*<m"]
281+
|===
282+
| name
283+
| "Bossman"
284+
| "George"
285+
| "George"
286+
| "Anders"
287+
d|Rows: 4
288+
|===
289+

modules/ROOT/pages/deprecations-additions-removals-compatibility.adoc

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,29 @@ RETURN cosh(0.5), coth(0.5), sinh(0.5), tanh(0.5)
307307
----
308308
| Introduction of four new hyperbolic trigonometric Cypher functions.
309309
For more information, see xref:functions/mathematical-trigonometric.adoc[Mathematical functions - trigonometric].
310+
311+
a|
312+
label:functionality[]
313+
label:new[]
314+
[source, cypher, role=noheader]
315+
----
316+
MATCH (n)
317+
RETURN ALL n.prop AS prop
318+
----
319+
| The keyword `ALL` can now be added after a xref:clauses/return.adoc#return-all-results[RETURN] as the explicit form of a `RETURN` without duplicate removal.
320+
321+
a|
322+
label:functionality[]
323+
label:new[]
324+
[source, cypher, role=noheader]
325+
----
326+
MATCH (n)
327+
WITH ALL n.prop AS prop
328+
RETURN prop
329+
----
330+
| The keyword `ALL` can now be added after a xref:clauses/with.adoc#with-all-results[WITH] as the explicit form of a `WITH` without duplicate removal.
331+
332+
310333
|===
311334

312335
[[cypher-deprecations-additions-removals-2025.03]]

0 commit comments

Comments
 (0)