Skip to content

Commit aef4d38

Browse files
post-review update
1 parent e3bd684 commit aef4d38

File tree

4 files changed

+43
-49
lines changed

4 files changed

+43
-49
lines changed

modules/ROOT/pages/clauses/create.adoc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ Properties set: 4
209209
[[dynamic-create]]
210210
== CREATE nodes and relationships using dynamic node labels and relationship types
211211

212-
Node labels and relationship types can be referenced dynamically in parameters and variables when creating nodes and relationships.
212+
Node labels and relationship types can be referenced dynamically in expressions, parameters, and variables when creating nodes and relationships.
213213

214214
.Syntax for creating nodes and relationships dynamically
215215
[source, syntax]
@@ -219,6 +219,8 @@ CREATE ()-[r:$(<expr>)]->()
219219
----
220220

221221
The expression must evaluate to a `STRING NOT NULL | LIST<STRING NOT NULL> NOT NULL` value.
222+
Using a `LIST<STRING>` with more than one item when creating a relationship using dynamic relationship types will fail.
223+
This is because a relationship can only have exactly one type.
222224

223225
.Parameters
224226
[source, parameters]

modules/ROOT/pages/clauses/match.adoc

Lines changed: 30 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ To recreate the graph, run the following query against an empty Neo4j database:
1717

1818
[source, cypher, role=test-setup]
1919
----
20-
CREATE (charlie:Person {name: 'Charlie Sheen'}),
21-
(martin:Person {name: 'Martin Sheen'}),
22-
(michael:Person {name: 'Michael Douglas'}),
23-
(oliver:Person {name: 'Oliver Stone'}),
24-
(rob:Person {name: 'Rob Reiner'}),
20+
CREATE (charlie:Person:Actor {name: 'Charlie Sheen'}),
21+
(martin:Person:Actor {name: 'Martin Sheen'}),
22+
(michael:Person:Actor {name: 'Michael Douglas'}),
23+
(oliver:Person:Director {name: 'Oliver Stone'}),
24+
(rob:Person:Director {name: 'Rob Reiner'}),
2525
(wallStreet:Movie {title: 'Wall Street'}),
2626
(charlie)-[:ACTED_IN {role: 'Bud Fox'}]->(wallStreet),
2727
(martin)-[:ACTED_IN {role: 'Carl Fox'}]->(wallStreet),
@@ -494,7 +494,7 @@ For more information about how Cypher queries work, see xref:clauses/clause-comp
494494
[[dynamic-match]]
495495
== MATCH nodes and relationships using dynamic node labels and relationship types
496496

497-
Node labels and relationship types can be referenced dynamically in parameters and variables when matching nodes and relationships.
497+
Node labels and relationship types can be referenced dynamically in expressions, parameters, and variables when matching nodes and relationships.
498498

499499
.Syntax for matching node labels dynamically
500500
[source, syntax]
@@ -504,6 +504,9 @@ MATCH (n:$any(<expr>))
504504
MATCH (n:$all(<expr>))
505505
----
506506

507+
[NOTE]
508+
`MATCH (n:$all(<expr>))` is functionally equivalent to `MATCH (n:$(<expr>))`.
509+
507510
.Syntax for matching relationship types dynamically
508511
[source, syntax]
509512
----
@@ -513,66 +516,50 @@ MATCH ()-[r:$all(<expr>))]->()
513516
----
514517

515518
The expression must evaluate to a `STRING NOT NULL | LIST<STRING NOT NULL> NOT NULL` value.
519+
If you use a `LIST<STRING>` with more than one item in a relationship pattern with dynamic relationship types, no results will be returned.
520+
This is because a relationship can only have exactly one type.
516521

517-
.Match labels dynamically using the `all()` function
522+
.Match labels dynamically
518523
[source, cypher]
519524
----
520-
WITH "Movie" AS label
521-
MATCH (movie:$all(label))
522-
RETURN movie AS movieNodes
525+
WITH ["Person", "Director"] AS labels
526+
MATCH (directors:$(labels))
527+
RETURN directors
523528
----
524529

525530
.Result
526531
[role="queryresult",options="header,footer",cols="1*<m"]
527532
|===
528-
| movieNodes
533+
| directors
529534

530-
| (:Movie {title: "Wall Street"})
531-
| (:Movie {title: "The American President"})
535+
| (:Person:Director {name: "Oliver Stone"})
536+
| (:Person:Director {name: "Rob Reiner"})
532537

533538
1+d|Rows: 2
534539
|===
535540

536-
[NOTE]
537-
The xref:functions/predicate.adoc#functions-all[`all()`] function matches nodes that have all the specified labels.
538-
539-
If passing a `LIST<STRING>` to an `all()` function evaluating a relationship pattern using dynamic relationship types, the list cannot contain more than one element.
540-
This is because a relationship can only have exactly one type.
541-
542-
.Attempting to match relationship patterns using more than one relationship type will not return any results
543-
[source, cypher]
544-
----
545-
MATCH ()-[r:$all(["ACTED_IN", "DIRECTED"])]->()
546-
RETURN r
547-
----
548-
549-
.Warning
550-
[source, warning]
551-
----
552-
Warning: The query contains a relationship type expression that cannot be satisfied.
553-
----
554-
555541
.Match nodes dynamically using the `any()` function
556542
[source, cypher]
557543
----
558-
MATCH (n:$any(["Movie", "Person"]))-[:ACTED_IN|DIRECTED]->(m:Movie)
559-
RETURN labels(n) AS labels, n.name AS person, collect(m.title) AS movies
544+
MATCH (n:$any(["Movie", "Actor"]))
545+
RETURN n as nodes
560546
----
561547

562548
[NOTE]
563549
The xref:functions/predicate.adoc#functions-any[`any()`] function matches nodes that have any of the specified labels.
564550

565551
.Result
566-
[role="queryresult",options="header,footer",cols="3*<m"]
552+
[role="queryresult",options="header,footer",cols="1*<m"]
567553
|===
568-
| labels | person | movies
569-
| ["Person"] | Charlie Sheen | ["Wall Street"]
570-
| ["Person"] | Martin Sheen | ["Wall Street", "The American President"]
571-
| ["Person"] | Michael Douglas | ["Wall Street", "The American President"]
572-
| ["Person"] | Oliver Stone | ["Wall Street"]
573-
| ["Person"] | Rob Reiner | ["The American President"]
554+
| nodes
555+
556+
| (:Person:Actor {name: "Charlie Sheen"})
557+
| (:Person:Actor {name: "Martin Sheen"})
558+
| (:Person:Actor {name: "Michael Douglas"})
559+
| (:Movie {title: "Wall Street"})
560+
| (:Movie {title: "The American President"})
574561

575-
3+d|Rows: 5
562+
1+d|Rows: 5
576563
|===
577564

578565

@@ -608,7 +595,7 @@ RETURN movie.title AS movieTitle
608595
----
609596
CALL db.relationshipTypes()
610597
YIELD relationshipType
611-
MATCH ()-[r:$(relationshipType)]-()
598+
MATCH ()-[r:$(relationshipType)]->()
612599
RETURN relationshipType, count(r) AS relationshipCount
613600
----
614601

modules/ROOT/pages/clauses/merge.adoc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,7 @@ RETURN person.name, person.bornIn, person.chauffeurName
688688
[[dynamic-merge]]
689689
== MERGE nodes and relationships using dynamic node labels and relationship types
690690

691-
Node labels and relationship types can be referenced dynamically in parameters and variables when merging nodes and relationships.
691+
Node labels and relationship types can be referenced dynamically in expressions, parameters, and variables when merging nodes and relationships.
692692

693693
.Syntax for merging nodes and relationships dynamically
694694
[source, syntax]
@@ -698,6 +698,8 @@ MERGE ()-[r:$(<expr>)]->()
698698
----
699699

700700
The expression must evaluate to a `STRING NOT NULL | LIST<STRING NOT NULL> NOT NULL` value.
701+
Using a `LIST<STRING>` with more than one item when merging a relationship using dynamic relationship types will fail.
702+
This is because a relationship can only have exactly one type.
701703

702704
.Parameters
703705
[source, parameters]

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,20 @@ label:functionality[]
8585
label:new[]
8686
[source, cypher, role="noheader"]
8787
----
88-
MATCH (movie:$($label))
88+
MATCH (movie:$($label)),
89+
()-[r:$($type))]->()
8990
----
9091

9192
[source, cypher, role="noheader"]
9293
----
93-
CREATE (movie:$($label))
94+
CREATE (movie:$($label)),
95+
()-[r:$($type)]->()
9496
----
9597

9698
[source, cypher, role="noheader"]
9799
----
98-
MERGE (movie:$($label))
100+
MERGE (movie:$($label)),
101+
()-[r:$($type)]->()
99102
----
100103

101104
[source, cypher, role="noheader"]
@@ -104,7 +107,7 @@ LOAD CSV WITH HEADERS FROM 'file:///artists-with-headers.csv' AS line
104107
CREATE (n:$(line.label) {name: line.Name})
105108
----
106109

107-
| Added the ability reference node labels and relationship types in xref:clauses/match.adoc#dynamic-match[`MATCH`], xref:clauses/create.adoc#dynamic-create[`CREATE`], and xref:clauses/merge.adoc#dynamic-merge[`MERGE`] clauses.
110+
| Added the ability to dynamically reference node labels and relationship types in xref:clauses/match.adoc#dynamic-match[`MATCH`], xref:clauses/create.adoc#dynamic-create[`CREATE`], and xref:clauses/merge.adoc#dynamic-merge[`MERGE`] clauses.
108111
Also introduced the ability to specify CSV columns dynamically when using xref:clauses/load-csv.adoc#dynamic-load[`LOAD CSV`].
109112
|===
110113

0 commit comments

Comments
 (0)