|
1 | 1 | = Sequential queries (`NEXT`) |
2 | | -:description: Information about how to use `NEXT` to construct conditional queries in Cypher. |
| 2 | +:description: Information about how to use `NEXT` to construct sequential queries in Cypher. |
3 | 3 | :page-role: new-2025.06 |
4 | 4 |
|
5 | | -//// |
6 | | -Benefits to this proposal |
| 5 | +`NEXT` allows for linear composition of queries into a sequence of smaller, self-contained segments while making return values from one segment available in the next. |
7 | 6 |
|
8 | | -Increases the modularity (and readability) of Cypher — allows for the partition of large queries into smaller, self contained modules that are possible to chain together using NEXT. |
9 | | -Decreases the reliance on CALL and WITH for constructing complex queries. |
10 | | -Improves usability of conditional and union queries. |
11 | | -Improves Cypher GQL conformance. |
12 | | -//// |
| 7 | +`NEXT` has a number of benefits: |
| 8 | + |
| 9 | +* `NEXT` can improve the modularity and readability of complex queries. |
| 10 | +* `NEXT` reduces the need to rely on the xref:clauses/call.adoc[CALL] and xref:clauses/with.adoc[] clauses to construct complex queries. |
| 11 | +* `NEXT` improves the usability of xref:queries/composed-queries/conditional-queries.adoc[conditional] and xref:queries/composed-queries/combined-queries.adoc[UNION] queries. |
| 12 | +
|
| 13 | +`NEXT` was introduced as part of Cypher's xref:appendix/gql-conformance/index.adoc[]. |
| 14 | + |
| 15 | + |
| 16 | + |
| 17 | +[[example-graph]] |
| 18 | +== Example graph |
| 19 | + |
| 20 | +The following graph is used for the examples on this page: |
| 21 | + |
| 22 | +image::conditional_query_graph.svg[width="700",role="middle"] |
| 23 | + |
| 24 | +To recreate the graph, run the following query against an empty Neo4j database: |
| 25 | + |
| 26 | +[source, cypher, role=test-setup] |
| 27 | +---- |
| 28 | +CREATE (alice:Person {name:'Alice', age: 65}), |
| 29 | + (bob:Person {name: 'Bob', age: 25}), |
| 30 | + (charlie:Person {name: 'Charlie', age: 61}), |
| 31 | + (daniel:Person {name: 'Daniel', age: 39}), |
| 32 | + (eskil:Person {name: 'Eskil', age: 39}), |
| 33 | + (bob)-[:WORKS_FOR]->(alice), |
| 34 | + (alice)-[:WORKS_FOR]->(daniel), |
| 35 | + (charlie)-[:WORKS_FOR]->(daniel), |
| 36 | + (bob)-[:LOVES]->(eskil), |
| 37 | + (charlie)-[:LOVES]->(alice) |
| 38 | +---- |
| 39 | + |
| 40 | + |
| 41 | +[[sequential-syntax]] |
| 42 | +== Syntax |
| 43 | + |
| 44 | +Lorem ipsum. |
| 45 | + |
| 46 | + |
| 47 | +[[sequential-rules]] |
| 48 | +== Rules |
| 49 | + |
| 50 | +Lorem ipsum. |
| 51 | + |
| 52 | +.Not allowed: not aliasing returned expressions |
| 53 | +[source, cypher, role=test-fail] |
| 54 | +---- |
| 55 | +WHEN true THEN RETURN 2 |
| 56 | +ELSE RETURN 3 |
| 57 | +---- |
| 58 | + |
| 59 | + |
| 60 | +== Using `NEXT` instead of `CALL` |
| 61 | + |
| 62 | +Lorem ipsum. |
| 63 | + |
| 64 | + |
| 65 | +== Using `NEXT` instead of `WITH` |
| 66 | + |
| 67 | +Lorem ipsum. |
| 68 | + |
| 69 | + |
| 70 | +== Interactions with conditional queries |
| 71 | + |
| 72 | +Lorem ipsum. |
| 73 | + |
| 74 | + |
| 75 | +== Interactions with `UNION` queries |
| 76 | + |
| 77 | +Lorem ipsum. |
0 commit comments