From 568655e9e08d3b9db1b4f7fd4699db35bedfc58e Mon Sep 17 00:00:00 2001 From: Gemma Lamont Date: Tue, 8 Jul 2025 11:20:37 +0200 Subject: [PATCH 1/2] Add dynamic label and type support in label expressions --- modules/ROOT/pages/clauses/filter.adoc | 32 +++++++++++++++++++ modules/ROOT/pages/clauses/where.adoc | 32 +++++++++++++++++++ ...ions-additions-removals-compatibility.adoc | 25 +++++++++++++++ modules/ROOT/pages/patterns/reference.adoc | 13 ++++++++ 4 files changed, 102 insertions(+) diff --git a/modules/ROOT/pages/clauses/filter.adoc b/modules/ROOT/pages/clauses/filter.adoc index fab35e07c..7514ecd73 100644 --- a/modules/ROOT/pages/clauses/filter.adoc +++ b/modules/ROOT/pages/clauses/filter.adoc @@ -93,6 +93,38 @@ RETURN p.name AS person, 3+|Rows: 2 |=== +[[filter-on-dynamic-labels-and-types]] +== Filter on dynamic labels and types + +To filter on a label or type using a dynamically computed value, use `$()`: + +.Parameters +[source, parameters] +---- +{ + "label": "Swedish" +} +---- + +.Filter on a dynamically computed node label +// tag::clauses_where_dynamic[] +[source, cypher] +---- +MATCH (n) +FILTER n:$($label) +RETURN labels(n) AS labels +---- +// end::clauses_where_dynamic[] + +.Result +[role="queryresult",options="header,footer",cols="1*)`: + +.Parameters +[source, parameters] +---- +{ + "label": "Swedish" +} +---- + +.Filter on a dynamically computed node label +// tag::clauses_where_dynamic[] +[source, cypher] +---- +MATCH (n) +WHERE n:$($label) +RETURN labels(n) AS labels +---- +// end::clauses_where_dynamic[] + +.Result +[role="queryresult",options="header,footer",cols="1*() +WHERE n:$() +WITH n, r:$() AS hasType +RETURN n:$() +---- + +| Added the ability to dynamically reference node labels and relationship types in places where xref:patterns/reference.adoc#label-expressions[label expressions] are allowed. +|=== + + [[cypher-deprecations-additions-removals-2025.06]] == Neo4j 2025.06 diff --git a/modules/ROOT/pages/patterns/reference.adoc b/modules/ROOT/pages/patterns/reference.adoc index 2cf0114ff..fcf9c4226 100644 --- a/modules/ROOT/pages/patterns/reference.adoc +++ b/modules/ROOT/pages/patterns/reference.adoc @@ -314,6 +314,19 @@ The following matches relationships that have a type that is neither `A` nor `B` -[:!A&!B]-> ---- +[[dynamic-label-and-type-expressions]] +=== Dynamic Label and Type expressions + +Node labels and relationship types can be referenced dynamically in expressions, parameters, and variables within label expressions. + +.Syntax for creating nodes and relationships dynamically +[source, syntax] +---- +dynamicLabelExpression ::= ":$(" + valueExpression ")" +---- + +The valueExpression must evaluate to a `STRING NOT NULL | LIST NOT NULL` value. + [[property-key-value-expressions]] == Property key-value expressions From 0cc0b3e15225c9acbe01d705bb7e0878b9d72c82 Mon Sep 17 00:00:00 2001 From: Gemma Lamont Date: Thu, 10 Jul 2025 10:48:27 +0200 Subject: [PATCH 2/2] PR updates --- modules/ROOT/pages/clauses/filter.adoc | 2 +- modules/ROOT/pages/clauses/where.adoc | 2 +- .../deprecations-additions-removals-compatibility.adoc | 6 +++--- modules/ROOT/pages/patterns/reference.adoc | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/modules/ROOT/pages/clauses/filter.adoc b/modules/ROOT/pages/clauses/filter.adoc index 7514ecd73..b51017673 100644 --- a/modules/ROOT/pages/clauses/filter.adoc +++ b/modules/ROOT/pages/clauses/filter.adoc @@ -96,7 +96,7 @@ RETURN p.name AS person, [[filter-on-dynamic-labels-and-types]] == Filter on dynamic labels and types -To filter on a label or type using a dynamically computed value, use `$()`: +To filter on a label or relationship type using a dynamically computed value, use `$()` where is any Cypher expression: .Parameters [source, parameters] diff --git a/modules/ROOT/pages/clauses/where.adoc b/modules/ROOT/pages/clauses/where.adoc index bf5e4d22f..2c747d4c8 100644 --- a/modules/ROOT/pages/clauses/where.adoc +++ b/modules/ROOT/pages/clauses/where.adoc @@ -106,7 +106,7 @@ RETURN f.name AS oldFriend [[filter-on-dynamic-labels-and-types]] == Filter on dynamic labels and types -To filter on a label or type using a dynamically computed value, use `$()`: +To filter on a label or relationship type using a dynamically computed value, use `$()` where is any Cypher expression: .Parameters [source, parameters] diff --git a/modules/ROOT/pages/deprecations-additions-removals-compatibility.adoc b/modules/ROOT/pages/deprecations-additions-removals-compatibility.adoc index f50447428..7378b91a4 100644 --- a/modules/ROOT/pages/deprecations-additions-removals-compatibility.adoc +++ b/modules/ROOT/pages/deprecations-additions-removals-compatibility.adoc @@ -38,9 +38,9 @@ label:updated[] [source, cypher, role="noheader"] ---- MATCH (n)-[r]->() -WHERE n:$() -WITH n, r:$() AS hasType -RETURN n:$() +WHERE n:$() +WITH n, r:$() AS hasType +RETURN n:$() ---- | Added the ability to dynamically reference node labels and relationship types in places where xref:patterns/reference.adoc#label-expressions[label expressions] are allowed. diff --git a/modules/ROOT/pages/patterns/reference.adoc b/modules/ROOT/pages/patterns/reference.adoc index fcf9c4226..a5009cfe8 100644 --- a/modules/ROOT/pages/patterns/reference.adoc +++ b/modules/ROOT/pages/patterns/reference.adoc @@ -315,7 +315,7 @@ The following matches relationships that have a type that is neither `A` nor `B` ---- [[dynamic-label-and-type-expressions]] -=== Dynamic Label and Type expressions +=== Dynamic label and type expressions Node labels and relationship types can be referenced dynamically in expressions, parameters, and variables within label expressions. @@ -325,7 +325,7 @@ Node labels and relationship types can be referenced dynamically in expressions, dynamicLabelExpression ::= ":$(" + valueExpression ")" ---- -The valueExpression must evaluate to a `STRING NOT NULL | LIST NOT NULL` value. +The `valueExpression` must evaluate to a `STRING NOT NULL | LIST NOT NULL` value. [[property-key-value-expressions]] == Property key-value expressions