From 7b1968d4439e2233be8542bf718a0d4136c584c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20Pryce-=C3=85klundh?= <112686610+JPryce-Aklundh@users.noreply.github.com> Date: Wed, 12 Mar 2025 15:19:52 +0100 Subject: [PATCH 1/7] initial --- modules/ROOT/pages/expressions/index.adoc | 2 ++ modules/ROOT/pages/expressions/string-operators.adoc | 12 ++++++++++++ 2 files changed, 14 insertions(+) create mode 100644 modules/ROOT/pages/expressions/string-operators.adoc diff --git a/modules/ROOT/pages/expressions/index.adoc b/modules/ROOT/pages/expressions/index.adoc index 49bb55a52..97415b831 100644 --- a/modules/ROOT/pages/expressions/index.adoc +++ b/modules/ROOT/pages/expressions/index.adoc @@ -12,4 +12,6 @@ For details and examples of specific expressions, see the following sections: ** xref:expressions/predicates/path-pattern-expressions.adoc[]: information about filtering queries with path pattern expressions. ** xref:expressions/predicates/type-predicate-expressions.adoc[]: information about how to verify the value type of a Cypher expression. * xref:expressions/mathematical-operators.adoc[]: `+`, `-`, `*`, `/`, `%`, `^`. +* xref:expressions/string-operators.adoc[]: `+`, `||` * xref:expressions/conditional-expressions.adoc[] + diff --git a/modules/ROOT/pages/expressions/string-operators.adoc b/modules/ROOT/pages/expressions/string-operators.adoc new file mode 100644 index 000000000..03b8ff307 --- /dev/null +++ b/modules/ROOT/pages/expressions/string-operators.adoc @@ -0,0 +1,12 @@ += String operators +:description: Information about Cypher's string operators. +:table-caption!: + +Cypher contains two functionally equivalent operators for the concatenation of `STRING` values: + +* `+` +* `||` + + +Using `+` to concatenate strings is functionally equivalent to using `||`. +However, the `+` string concatenation operator is not xref:appendix/gql-conformance/index.adoc[GQL conformant]. From 5e3a9232ab87735ce47306a88c20778f7587a017 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20Pryce-=C3=85klundh?= <112686610+JPryce-Aklundh@users.noreply.github.com> Date: Wed, 12 Mar 2025 16:10:38 +0100 Subject: [PATCH 2/7] second --- modules/ROOT/content-nav.adoc | 1 + .../pages/expressions/string-operators.adoc | 27 +++++++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/modules/ROOT/content-nav.adoc b/modules/ROOT/content-nav.adoc index a04a1db7f..033767527 100644 --- a/modules/ROOT/content-nav.adoc +++ b/modules/ROOT/content-nav.adoc @@ -74,6 +74,7 @@ *** xref:expressions/predicates/path-pattern-expressions.adoc[] *** xref:expressions/predicates/type-predicate-expressions.adoc[] ** xref:expressions/mathematical-operators.adoc[] +** xref:expressions/string-operators.adoc[] ** xref:expressions/conditional-expressions.adoc[] * xref:functions/index.adoc[] diff --git a/modules/ROOT/pages/expressions/string-operators.adoc b/modules/ROOT/pages/expressions/string-operators.adoc index 03b8ff307..b77c55902 100644 --- a/modules/ROOT/pages/expressions/string-operators.adoc +++ b/modules/ROOT/pages/expressions/string-operators.adoc @@ -7,6 +7,29 @@ Cypher contains two functionally equivalent operators for the concatenation of ` * `+` * `||` +`||` is xref:appendix/gql-conformance/index.adoc[GQL conformant], `+` is not. + +For additional expressions evaluating `STRING` values, see xref:functions/string.adoc[String functions]. + +[[examples]] +== Examples + +.`||` and `+` +[source, cypher] +---- +RETURN 'concatenatedWith' || '||' AS result1 + 'concatenatedWith' + '+' AS result2 +---- + +.Result +[role="queryresult",options="header,footer",cols="2* Date: Thu, 13 Mar 2025 10:12:05 +0100 Subject: [PATCH 3/7] third --- .../pages/expressions/string-operators.adoc | 110 ++++++++++++++++-- 1 file changed, 102 insertions(+), 8 deletions(-) diff --git a/modules/ROOT/pages/expressions/string-operators.adoc b/modules/ROOT/pages/expressions/string-operators.adoc index b77c55902..9bd5862cd 100644 --- a/modules/ROOT/pages/expressions/string-operators.adoc +++ b/modules/ROOT/pages/expressions/string-operators.adoc @@ -1,15 +1,16 @@ -= String operators += String concatenation operators :description: Information about Cypher's string operators. :table-caption!: -Cypher contains two functionally equivalent operators for the concatenation of `STRING` values: +Cypher contains two operators for the concatenation of `STRING` values: -* `+` * `||` +* `+` -`||` is xref:appendix/gql-conformance/index.adoc[GQL conformant], `+` is not. +The two operators are functionally equivalent. +However, `||` is xref:appendix/gql-conformance/index.adoc[GQL conformant], while `+` is not. -For additional expressions evaluating `STRING` values, see xref:functions/string.adoc[String functions]. +For additional expressions that evaluate `STRING` values, see xref:functions/string.adoc[String functions]. [[examples]] == Examples @@ -17,8 +18,8 @@ For additional expressions evaluating `STRING` values, see xref:functions/string .`||` and `+` [source, cypher] ---- -RETURN 'concatenatedWith' || '||' AS result1 - 'concatenatedWith' + '+' AS result2 +RETURN 'Neo' || '4j' AS result1 + 'Neo' + '4j' AS result2 ---- .Result @@ -26,10 +27,103 @@ RETURN 'concatenatedWith' || '||' AS result1 |=== | result1 | result2 -| "concatenatedWith||" | "concatenatedWith+" +| "Neo4j" | "Neo4j" 2+d|Rows: 1 |=== +The xref:functions/string.adoc#functions-tostring[`toString()`] function can be used to concatenate non-`STRING` values into a `STRING` value. + +.Concatenation using `toString()` function +[source, cypher] +---- +RETURN 'The number is: ' || toString(42) AS result +---- + +.Result +[role="queryresult",options="header,footer",cols="1* Date: Thu, 13 Mar 2025 10:14:49 +0100 Subject: [PATCH 4/7] remove section on old operators page --- modules/ROOT/pages/functions/string.adoc | 2 +- modules/ROOT/pages/syntax/operators.adoc | 50 ------------------------ 2 files changed, 1 insertion(+), 51 deletions(-) diff --git a/modules/ROOT/pages/functions/string.adoc b/modules/ROOT/pages/functions/string.adoc index 21e882134..4a843d4a7 100644 --- a/modules/ROOT/pages/functions/string.adoc +++ b/modules/ROOT/pages/functions/string.adoc @@ -16,7 +16,7 @@ When `toString()` is applied to a temporal value, it returns a `STRING` represen This `STRING` will therefore be formatted according to the https://en.wikipedia.org/wiki/ISO_8601[ISO 8601] format. ==== -See also xref::syntax/operators.adoc#query-operators-string[String operators]. +See also xref::expressions/string-operators.adoc[String concatenation operators]. [[functions-btrim]] diff --git a/modules/ROOT/pages/syntax/operators.adoc b/modules/ROOT/pages/syntax/operators.adoc index c5f6e9c77..5581e7f7e 100644 --- a/modules/ROOT/pages/syntax/operators.adoc +++ b/modules/ROOT/pages/syntax/operators.adoc @@ -12,7 +12,6 @@ This page contains an overview of the available Cypher operators. |=== | xref::syntax/operators.adoc#query-operators-aggregation[Aggregation operators] | `DISTINCT` | xref::syntax/operators.adoc#query-operators-property[Property operators] | `.` for static property access, `[]` for dynamic property access, `=` for replacing all properties, `+=` for mutating specific properties -| xref::syntax/operators.adoc#query-operators-string[String operators] | `+` and `\|\|` (string concatenation), `IS NORMALIZED` | xref::syntax/operators.adoc#query-operators-temporal[Temporal operators] | `+` and `-` for operations between durations and temporal instants/durations, `*` and `/` for operations between durations and numbers | xref::syntax/operators.adoc#query-operators-map[Map operators] | `.` for static value access by key, `[]` for dynamic value access by key | xref::syntax/operators.adoc#query-operators-list[List operators] | `+` and `\|\|` (list concatenation), `IN` to check existence of an element in a list, `[]` for accessing element(s) dynamically @@ -188,55 +187,6 @@ The properties on the node are updated as follows by those provided in the map: See xref::clauses/set.adoc#set-setting-properties-using-map[Mutate specific properties using a map and `+=`] for more details on using the property mutation operator `+=`. -[[query-operators-string]] -== String operators - -The string operators comprise: - -* concatenating `STRING` values: `+` and `||` -* checking if a `STRING` is normalized: `IS NORMALIZED` - -[[syntax-concatenating-two-strings]] -=== Concatenating two `STRING` values with `+` - -Using `+` to concatenate strings is functionally equivalent to using `||`. -However, the `+` string concatenation operator is not xref:appendix/gql-conformance/index.adoc[GQL conformant]. - -.Query -[source, cypher] ----- -RETURN 'neo' + '4j' AS result ----- - -.Result -[role="queryresult",options="header,footer",cols="1* Date: Thu, 13 Mar 2025 10:42:45 +0100 Subject: [PATCH 5/7] consistent use of || --- modules/ROOT/pages/expressions/string-operators.adoc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/ROOT/pages/expressions/string-operators.adoc b/modules/ROOT/pages/expressions/string-operators.adoc index 9bd5862cd..949df4eef 100644 --- a/modules/ROOT/pages/expressions/string-operators.adoc +++ b/modules/ROOT/pages/expressions/string-operators.adoc @@ -66,7 +66,7 @@ RETURN 'Alpha' || 'Beta' AS result1, | "AlphaBeta" | "Alpha Beta" -1+d| Rows: 1 +2+d| Rows: 1 |=== .Concatenating `STRING` properties @@ -92,7 +92,7 @@ RETURN p.fullName AS fullName .Concatenate `STRING` values in a `LIST` [source, cypher] ---- -RETURN reduce(acc = '', item IN ['Neo', '4j'] | acc + item) AS result +RETURN reduce(acc = '', item IN ['Neo', '4j'] | acc || item) AS result ---- .Result @@ -115,7 +115,7 @@ This ensures that all `NULL` values are effectively skipped, allowing the `reduc [source, cypher] ---- WITH ['Neo', NULL, '4j', NULL, 'Hello', NULL] AS items -RETURN reduce(acc = '', item IN items | acc + coalesce(item, '')) AS result +RETURN reduce(acc = '', item IN items | acc || coalesce(item, '')) AS result ---- .Result From 36c4080b4361ffd28512cddef3f09e88d16e5524 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20Pryce-=C3=85klundh?= <112686610+JPryce-Aklundh@users.noreply.github.com> Date: Thu, 13 Mar 2025 15:09:53 +0100 Subject: [PATCH 6/7] more examples --- .../pages/expressions/string-operators.adoc | 116 ++++++++++++++++-- 1 file changed, 107 insertions(+), 9 deletions(-) diff --git a/modules/ROOT/pages/expressions/string-operators.adoc b/modules/ROOT/pages/expressions/string-operators.adoc index 949df4eef..f656d8ffb 100644 --- a/modules/ROOT/pages/expressions/string-operators.adoc +++ b/modules/ROOT/pages/expressions/string-operators.adoc @@ -1,5 +1,5 @@ = String concatenation operators -:description: Information about Cypher's string operators. +:description: Information about Cypher's string concatenation operators. :table-caption!: Cypher contains two operators for the concatenation of `STRING` values: @@ -10,7 +10,7 @@ Cypher contains two operators for the concatenation of `STRING` values: The two operators are functionally equivalent. However, `||` is xref:appendix/gql-conformance/index.adoc[GQL conformant], while `+` is not. -For additional expressions that evaluate `STRING` values, see xref:functions/string.adoc[String functions]. +For additional expressions that evaluate to `STRING` values, see xref:functions/string.adoc[String functions]. [[examples]] == Examples @@ -18,7 +18,7 @@ For additional expressions that evaluate `STRING` values, see xref:functions/str .`||` and `+` [source, cypher] ---- -RETURN 'Neo' || '4j' AS result1 +RETURN 'Neo' || '4j' AS result1, 'Neo' + '4j' AS result2 ---- @@ -87,12 +87,48 @@ RETURN p.fullName AS fullName 1+d| Rows: 1 |=== +.Adding separators in `STRING` concatenation +[source, cypher] +---- +RETURN 'Hello' || ', ' || 'World' AS result +---- + +.Result +[role="queryresult",options="header,footer",cols="1* Date: Fri, 14 Mar 2025 14:49:12 +0100 Subject: [PATCH 7/7] clean up --- modules/ROOT/pages/expressions/string-operators.adoc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/modules/ROOT/pages/expressions/string-operators.adoc b/modules/ROOT/pages/expressions/string-operators.adoc index f656d8ffb..e0fd193e0 100644 --- a/modules/ROOT/pages/expressions/string-operators.adoc +++ b/modules/ROOT/pages/expressions/string-operators.adoc @@ -120,7 +120,7 @@ RETURN 'My favorite fruits are: ' || 'apples' || ', ' || 'bananas' || ', and' || |=== [[list-values-and-null]] -== String concatenation,`LIST` values, and `NULL` +== String concatenation, `LIST` values, and `NULL` `STRING` values in a `LIST` can be concatenated using the xref:functions/list.adoc#functions-reduce[`reduce()`] function. @@ -206,8 +206,7 @@ RETURN 'My favorite fruits are: ' || coalesce(reduce(acc = head(list), item IN t 1+d|Rows: 3 |=== -Finally, xref:values-and-types/lists.adoc#cypher-list-comprehension[ -list comprehension] allows concatenating a `STRING` value to each item in a `LIST` to generate a new `LIST` of modified `STRING` values. +Additionally, xref:values-and-types/lists.adoc#cypher-list-comprehension[list comprehension] allows concatenating a `STRING` value to each item in a `LIST` to generate a new `LIST` of modified `STRING` values. .List comprehension with `STRING` concatenation on `LIST` items [source, cypher]