|
8 | 8 | `NEXT` has the following benefits: |
9 | 9 |
|
10 | 10 | * `NEXT` can improve the modularity and readability of complex queries. |
11 | | -* `NEXT` can be used instead of xref:subqueries/call-subquery.adoc[] and the xref:clauses/with.adoc[] clause to construct complex queries. |
12 | | -* `NEXT` can improve the usability of xref:queries/composed-queries/conditional-queries.adoc[conditional `WHEN`] and xref:queries/composed-queries/combined-queries.adoc[combined `UNION`] queries. |
| 11 | +* `NEXT` can be used instead of xref:clauses/with.adoc[] clause to construct complex queries. |
| 12 | +* `NEXT` can improve the usability of xref:queries/composed-queries/conditional-queries.adoc[conditional `WHEN`] |
| 13 | +* `NEXT` allows for passing the full working table into xref:queries/composed-queries/combined-queries.adoc[combined `UNION`] queries. |
13 | 14 |
|
14 | 15 | [[example-graph]] |
15 | 16 | == Example graph |
@@ -383,12 +384,45 @@ RETURN customer.firstName AS plantCustomer |
383 | 384 | 1+d|Rows: 6 |
384 | 385 | |=== |
385 | 386 |
|
| 387 | +=== Leveraging by-table semantics using `UNION` after `NEXT` |
| 388 | +If a `UNION` query follows a `NEXT` in any of its blocks, it will pass the full working table into all arms of the `UNION` query. |
386 | 389 |
|
387 | | -[[next-unsupported-behavior]] |
388 | | -== Known limitations |
| 390 | +.By-table semantics using `NEXT` |
| 391 | +[source, cypher] |
| 392 | +---- |
| 393 | + MATCH (c:Customer)-[:BUYS]->(p:Product) |
| 394 | + RETURN c, p |
| 395 | +
|
| 396 | + NEXT |
| 397 | +
|
| 398 | + RETURN c.firstName AS name, COLLECT(p.price * c.discount) AS purchases, "discounted price" AS type |
| 399 | + UNION |
| 400 | + RETURN c.firstName AS name, COLLECT(p.price) AS purchases, "real price" AS type |
| 401 | +
|
| 402 | + NEXT |
389 | 403 |
|
390 | | -`NEXT` currently does not support the following when they are used in a `UNION` query, wrapped in braces or after a `USE` clause: |
| 404 | + RETURN * ORDER BY name, type |
| 405 | +---- |
391 | 406 |
|
392 | | -* updating queries such as `CREATE` or `MERGE`, |
393 | | -* `DISTINCT`, |
394 | | -* aggregations. |
| 407 | +.Result |
| 408 | +[role="queryresult",options="header,footer",cols="3*<m"] |
| 409 | +|=== |
| 410 | +| name | purchases | type |
| 411 | + |
| 412 | +| Amir | [100.0, 0.5] | discounted price |
| 413 | +| Amir | [1000, 5] | real price |
| 414 | +| Hannah | [37.5, 1.5] | discounted price |
| 415 | +| Hannah | [250, 10] | real price |
| 416 | +| Keisha | [50.0] | discounted price |
| 417 | +| Keisha | [250] | real price |
| 418 | +| Leila | [100.0] | discounted price |
| 419 | +| Leila | [1000] | real price |
| 420 | +| Mateo | [50.0, 0.25, 0.5] | discounted price |
| 421 | +| Mateo | [1000, 5, 10] | real price |
| 422 | +| Niko | [125.0, 62.5, 2.5] | discounted price |
| 423 | +| Niko | [500, 250, 10] | real price |
| 424 | +| Yusuf | [100.0, 0.5] | discounted price |
| 425 | +| Yusuf | [1000, 5] | real price |
| 426 | + |
| 427 | +3+d|Rows: 14 |
| 428 | +|=== |
0 commit comments