-
Notifications
You must be signed in to change notification settings - Fork 64
Dynamic labels/types #1098
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dynamic labels/types #1098
Changes from 8 commits
edec296
47a4162
84d1ae6
6990444
fa24662
5131a8d
cfc3da4
e3bd684
aef4d38
2a3579a
270ff81
b614ba2
007d488
ed4ff85
e9debb3
d7a126a
6912c0d
051e14e
06fac3b
a2211f0
39581df
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -205,6 +205,57 @@ Nodes created: 2 + | |||||
| Properties set: 4 | ||||||
| |=== | ||||||
|
|
||||||
| [role=label--new-5.26] | ||||||
| [[dynamic-create]] | ||||||
| == CREATE nodes and relationships using dynamic node labels and relationship types | ||||||
|
|
||||||
| Node labels and relationship types can be referenced dynamically in parameters and variables when creating nodes and relationships. | ||||||
|
||||||
|
|
||||||
| .Syntax for creating nodes and relationships dynamically | ||||||
| [source, syntax] | ||||||
| ---- | ||||||
| CREATE (n:$(<expr>)), | ||||||
|
||||||
| CREATE (n:$(<expr>)), | |
| CREATE (n:$(<expr>)) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -490,3 +490,135 @@ The above query uses the xref:functions/aggregating.adoc#functions-collect[`coll | |
|
|
||
| For more information about how Cypher queries work, see xref:clauses/clause-composition.adoc[]. | ||
|
|
||
| [role=label--new-5.26] | ||
| [[dynamic-match]] | ||
| == MATCH nodes and relationships using dynamic node labels and relationship types | ||
|
||
|
|
||
| Node labels and relationship types can be referenced dynamically in parameters and variables when matching nodes and relationships. | ||
|
||
|
|
||
| .Syntax for matching node labels dynamically | ||
| [source, syntax] | ||
| ---- | ||
| MATCH (n:$(<expr>)) | ||
| MATCH (n:$any(<expr>)) | ||
| MATCH (n:$all(<expr>)) | ||
| ---- | ||
|
|
||
| .Syntax for matching relationship types dynamically | ||
| [source, syntax] | ||
| ---- | ||
| MATCH ()-[r:$(<expr>))]->() | ||
| MATCH ()-[r:$any(<expr>)]->() | ||
| MATCH ()-[r:$all(<expr>))]->() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can it be specified that all and not specifying one are the same meaning? |
||
| ---- | ||
|
|
||
| The expression must evaluate to a `STRING NOT NULL | LIST<STRING NOT NULL> NOT NULL` value. | ||
|
|
||
| .Match labels dynamically using the `all()` function | ||
| [source, cypher] | ||
| ---- | ||
| WITH "Movie" AS label | ||
| MATCH (movie:$all(label)) | ||
| RETURN movie AS movieNodes | ||
|
||
| ---- | ||
|
|
||
| .Result | ||
| [role="queryresult",options="header,footer",cols="1*<m"] | ||
| |=== | ||
| | movieNodes | ||
|
|
||
| | (:Movie {title: "Wall Street"}) | ||
| | (:Movie {title: "The American President"}) | ||
|
|
||
| 1+d|Rows: 2 | ||
| |=== | ||
|
|
||
| [NOTE] | ||
| The xref:functions/predicate.adoc#functions-all[`all()`] function matches nodes that have all the specified labels. | ||
|
|
||
| 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. | ||
|
||
| This is because a relationship can only have exactly one type. | ||
|
|
||
| .Attempting to match relationship patterns using more than one relationship type will not return any results | ||
| [source, cypher] | ||
| ---- | ||
| MATCH ()-[r:$all(["ACTED_IN", "DIRECTED"])]->() | ||
| RETURN r | ||
| ---- | ||
|
|
||
| .Warning | ||
| [source, warning] | ||
| ---- | ||
| Warning: The query contains a relationship type expression that cannot be satisfied. | ||
| ---- | ||
|
|
||
| .Match nodes dynamically using the `any()` function | ||
| [source, cypher] | ||
| ---- | ||
| MATCH (n:$any(["Movie", "Person"]))-[:ACTED_IN|DIRECTED]->(m:Movie) | ||
| RETURN labels(n) AS labels, n.name AS person, collect(m.title) AS movies | ||
|
||
| ---- | ||
|
|
||
| [NOTE] | ||
| The xref:functions/predicate.adoc#functions-any[`any()`] function matches nodes that have any of the specified labels. | ||
|
||
|
|
||
| .Result | ||
| [role="queryresult",options="header,footer",cols="3*<m"] | ||
| |=== | ||
| | labels | person | movies | ||
| | ["Person"] | Charlie Sheen | ["Wall Street"] | ||
| | ["Person"] | Martin Sheen | ["Wall Street", "The American President"] | ||
| | ["Person"] | Michael Douglas | ["Wall Street", "The American President"] | ||
| | ["Person"] | Oliver Stone | ["Wall Street"] | ||
| | ["Person"] | Rob Reiner | ["The American President"] | ||
|
|
||
| 3+d|Rows: 5 | ||
| |=== | ||
|
|
||
|
|
||
| .Parameter | ||
| [source, parameters] | ||
| ---- | ||
| { | ||
| "label": "Movie" | ||
| } | ||
| ---- | ||
|
|
||
| .Match nodes dynamically using a parameter | ||
| [source, cypher] | ||
| ---- | ||
| MATCH (movie:$($label)) | ||
| RETURN movie.title AS movieTitle | ||
| ---- | ||
|
|
||
| .Result | ||
| [role="queryresult",options="header,footer",cols="1*<m"] | ||
| |=== | ||
| | movieTitle | ||
|
|
||
| | "Wall Street" | ||
| | "The American President" | ||
|
|
||
| 1+d|Rows: 2 | ||
| |=== | ||
|
|
||
|
|
||
| .Match relationships dynamically using a variable | ||
| [source, cypher] | ||
| ---- | ||
| CALL db.relationshipTypes() | ||
| YIELD relationshipType | ||
| MATCH ()-[r:$(relationshipType)]-() | ||
| RETURN relationshipType, count(r) AS relationshipCount | ||
| ---- | ||
|
|
||
| .Result | ||
| [role="queryresult",options="header,footer",cols="2*<m"] | ||
| |=== | ||
| | relationshipType | relationshipCount | ||
|
|
||
| | "ACTED_IN" | 5 | ||
| | "DIRECTED" | 2 | ||
|
|
||
| 2+d|Rows: 2 | ||
| |=== | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -683,3 +683,55 @@ RETURN person.name, person.bornIn, person.chauffeurName | |||||
| | person.name | person.bornIn | person.chauffeurName | ||||||
| | "Keanu Reeves" | "Beirut" | "Eric Brown" | ||||||
| |=== | ||||||
|
|
||||||
| [role=label--new-5.26] | ||||||
| [[dynamic-merge]] | ||||||
| == MERGE nodes and relationships using dynamic node labels and relationship types | ||||||
|
||||||
|
|
||||||
| Node labels and relationship types can be referenced dynamically in parameters and variables when merging nodes and relationships. | ||||||
|
||||||
|
|
||||||
| .Syntax for merging nodes and relationships dynamically | ||||||
| [source, syntax] | ||||||
| ---- | ||||||
| MERGE (n:$(<expr>)), | ||||||
|
||||||
| MERGE (n:$(<expr>)), | |
| MERGE (n:$(<expr>)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be good to mention maybe that relationships can still only have one type, even if a list is supplied
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a really long title, is it possible to make it shorter?
CREATE using dynamic node labels and relationship typesperhaps?