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
Copy file name to clipboardExpand all lines: modules/ROOT/pages/expressions/list-expressions.adoc
+13-14Lines changed: 13 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -55,7 +55,7 @@ RETURN [1,2] || [3,4] AS list1,
55
55
2+d|Rows: 1
56
56
|===
57
57
58
-
.Concatenating two `LIST` properties
58
+
.Concatenate two `LIST` properties
59
59
[source, cypher]
60
60
----
61
61
MATCH (cecil:Person {name: 'Cecil'}), (cecilia:Person {name: 'Cecilia'})
@@ -75,7 +75,7 @@ RETURN cecil.skills || cecilia.skills AS combinedSkills
75
75
The `+` operator can add elements to the beginning or end of a `LIST` value.
76
76
This is not possible using the `||` operator.
77
77
78
-
.Adding elements to the beginning of a `LIST`
78
+
.Add elements to the beginning and end of a `LIST`
79
79
[source, cypher]
80
80
----
81
81
WITH [1, 2, 3, 4] AS list
@@ -94,7 +94,7 @@ RETURN 0 + list AS newBeginning,
94
94
2+d|Rows: 1
95
95
|===
96
96
97
-
.Adding elements to the beginning of a `LIST` property `+`
97
+
.Add elements to the beginning of a `LIST` property
98
98
[source, cypher]
99
99
----
100
100
MATCH (cecil:Person {name: 'Cecil'})
@@ -114,7 +114,7 @@ RETURN cecil.skills AS skillsList
114
114
115
115
If `NULL` is part of a concatenated `LIST`, `NULL` will be a part of the new `LIST`.
116
116
117
-
.Concatenating `LIST` including `NULL`
117
+
.Concatenate `LIST` including `NULL`
118
118
[source, cypher]
119
119
----
120
120
RETURN [1, 2] || [3, null] AS listWithNull
@@ -139,7 +139,7 @@ The subscript operator, `[]`, can be used to access specific elements in a `LIST
139
139
`[0]` refers to the first element in a `LIST`, `[1]` to the second, and so on.
140
140
`[-1]` refers to the last element in a `LIST`, `[-2]` to the penultimate element, and so on.
141
141
142
-
.Accessing individual elements in a `LIST`
142
+
.Access individual elements in a `LIST`
143
143
[source, cypher]
144
144
----
145
145
WITH [1, 2, 3, 4] AS list
@@ -168,7 +168,7 @@ The index of the element in the `LIST` can be parameterized.
168
168
}
169
169
----
170
170
171
-
.Accessing `LIST` elements with a parameter
171
+
.Access `LIST` elements with a parameter
172
172
[source, cypher]
173
173
----
174
174
WITH [1, 2, 3, 4] AS list
@@ -185,7 +185,7 @@ RETURN list[$myIndex] AS secondElement
185
185
1+d|Rows: 1
186
186
|===
187
187
188
-
.Accessing a `LIST` within a nested `LIST`
188
+
.Access a `LIST` within a nested `LIST`
189
189
[source, cypher]
190
190
----
191
191
WITH [[1, 2], [3, 4], [5, 6]] AS nestedList
@@ -204,7 +204,7 @@ RETURN nestedList[1] AS secondList
204
204
205
205
The xref:expressions/predicates/list-operators.adoc[`IN`] operator, which checks for `LIST` membership, can be used together with `[]` to test whether an element exists in a nested `LIST`.
206
206
207
-
.Checking for membership in nested `LIST`
207
+
.Check for membership in a nested `LIST`
208
208
[source, cypher]
209
209
----
210
210
WITH [[1, 2, 3], [4, 5, 6]] AS nestedList
@@ -223,7 +223,7 @@ RETURN 3 IN nestedList[0] AS elementPresent
223
223
224
224
Attempting to reference an element outside the bounds of the `LIST` will return `NULL`, as will attempting to access elements from an empty `LIST`.
225
225
226
-
.Out-of-bounds and empty list access
226
+
.Out-of-bounds and empty `LIST` access
227
227
[source, cypher]
228
228
----
229
229
WITH [1, 2, 3, 4] AS list, [] AS emptyList
@@ -308,7 +308,7 @@ RETURN nestedList[1][0..2] AS slicedInnerList
308
308
309
309
Accessing specific elements or a range of elements can also be used in combination with the `+` operator to create a new `LIST` with values inserted into specific sections of an existing `LIST` value.
310
310
311
-
.Inserting elements into specific positions of a `LIST`
311
+
.Insert elements into specific positions of a `LIST`
312
312
[source, cypher]
313
313
----
314
314
WITH [1, 3, 4] AS list
@@ -390,7 +390,7 @@ RETURN [n IN list WHERE n > 2 | n] AS filteredList
390
390
391
391
This below query iterates over the `skills` property of each Person node and creates a new `LIST` by xref:expressions/string-operators.adoc[concatenating the `STRING`] `" expert"` to each element in `skills`.
392
392
393
-
.Modify `LIST` properties
393
+
.Modify `LIST` properties using list comprehension
394
394
[source, cypher]
395
395
----
396
396
MATCH (p:Person) WHERE p.skills IS NOT NULL
@@ -434,10 +434,9 @@ RETURN [person IN collect(p) WHERE 'Python' IN person.skills | person.name] AS p
434
434
1+d|Rows: 1
435
435
|===
436
436
437
-
438
437
List comprehension can be used to remove any unknown `NULL` values when concatenating `LIST` values.
439
438
440
-
.Use a list comprehension to remove `NULL` values during list concatenation
439
+
.List comprehension to remove `NULL` values during list concatenation
441
440
[source, cypher]
442
441
----
443
442
RETURN [x IN ([1, null, 3] || [null, 5, null]) WHERE x IS NOT NULL] AS listWithoutNull
@@ -513,7 +512,7 @@ RETURN [(cecil)-[:WORKS_FOR]->+(superior:Person) | superior.skills] AS superiors
513
512
----
514
513
515
514
Pattern comprehension only supports only the xref:patterns/reference.adoc#variable-length-relationships[variable-length relationships] syntax.
516
-
The belowquery uses a pattern comprehension to collect the skills of all superiors in the chain above `Cecil`.
515
+
The below query uses a pattern comprehension to collect the skills of all superiors in the chain above `Cecil`.
517
516
The xref:functions/list.adoc#functions-reduce[`reduce()`] function concatenates these skills into a single `LIST`, and xref:clauses/unwind.adoc[`UNWIND`] is used to flatten this `LIST` before returning the distinct skills in a new `LIST`.
518
517
519
518
.Allowed - pattern comprehension to match patterns of a variable length using variable-length relationship syntax
0 commit comments