You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
| "My favorite fruits are: apples, bananas, and oranges."
118
+
119
+
1+d| Rows: 1
120
+
|===
121
+
122
+
[[list-values-and-null]]
123
+
== String concatenation,`LIST` values, and `NULL`
124
+
90
125
`STRING` values in a `LIST` can be concatenated using the xref:functions/list.adoc#functions-reduce[`reduce()`] function.
91
126
92
127
.Concatenate `STRING` values in a `LIST`
93
128
[source, cypher]
94
129
----
95
-
RETURN reduce(acc = '', item IN ['Neo', '4j'] | acc || item) AS result
130
+
WITH ['Neo', '4j'] AS list
131
+
RETURN reduce(acc = '', item IN list| acc || item) AS result
96
132
----
97
133
98
134
.Result
@@ -105,25 +141,87 @@ RETURN reduce(acc = '', item IN ['Neo', '4j'] | acc || item) AS result
105
141
1+d| Rows: 1
106
142
|===
107
143
144
+
The following query uses the xref:functions/scalar.adoc#functions-head[`head()`] function to start the accumulator with the first `item` in the `list`, while the xref:functions/scalar.adoc#functions-tail[`tail()`] function returns the remaining items in the `list`.
145
+
The `reduce()` function then concatenates these items with commas.
146
+
147
+
.Add prefix and a separator (`,`) in a `STRING` concatenated from `STRING` values in a `LIST`
148
+
[source, cypher]
149
+
----
150
+
WITH ['Apples', 'Bananas', 'Oranges'] AS list
151
+
RETURN 'My favorite fruits are: ' || reduce(acc = head(list), item IN tail(list) | acc || ', ' || item) || '.' AS result
0 commit comments