List functions
List functions return lists of different data entities.
For more information about working with LIST values, see:
Example graph
The following graph is used for the examples below:
To recreate the graph, run the following query against an empty Neo4j database:
CREATE
(alice:Developer {name:'Alice', age: 38, eyes: 'Brown'}),
(bob:Administrator {name: 'Bob', age: 25, eyes: 'Blue'}),
(charlie:Administrator {name: 'Charlie', age: 53, eyes: 'Green'}),
(daniel:Administrator {name: 'Daniel', age: 54, eyes: 'Brown'}),
(eskil:Designer {name: 'Eskil', age: 41, eyes: 'blue', likedColors: ['Pink', 'Yellow', 'Black']}),
(alice)-[:KNOWS]->(bob),
(alice)-[:KNOWS]->(charlie),
(bob)-[:KNOWS]->(daniel),
(charlie)-[:KNOWS]->(daniel),
(bob)-[:MARRIED]->(eskil)
coll.distinct()
Syntax |
|
||
Description |
Returns the given list with all duplicate values removed. |
||
Arguments |
Name |
Type |
Description |
|
|
A list to be deduplicated. |
|
Returns |
|
||
|
The order of the first occurrences of the distinct values is preserved. |
RETURN coll.distinct([1, 3, 2, 4, 2, 3, 1])
A LIST<ANY> containing only unique values is returned.
| coll.distinct([1, 3, 2, 4, 2, 3, 1]) |
|---|
|
Rows: 1 |
RETURN coll.distinct([1, true, true, null, 'a', false, true, 1, null])
A LIST<ANY> containing only unique values is returned.
| coll.distinct([1, true, true, null, 'a', false, true, 1, null]) |
|---|
|
Rows: 1 |
coll.flatten()
Syntax |
|
||
Description |
Returns a list flattened to the given nesting depth. |
||
Arguments |
Name |
Type |
Description |
|
|
A nested list to be flattened. |
|
|
|
The maximum depth to flatten to (default value: 1). |
|
Returns |
|
||
Preserves the original order of non-list items. |
If |
|
|
|
|
|
RETURN coll.flatten(['a', ['b', ['c']]], 2)
A LIST<ANY> with any inner lists up to a nesting depth of 2 flattened.
| coll.flatten(['a', ['b', ['c']]], 2) |
|---|
|
Rows: 1 |
RETURN coll.flatten(['a', ['b', ['c']]])
A LIST<ANY> with any inner lists up to a nesting depth of 1 (default depth) flattened.
| coll.flatten(['a', ['b', ['c']]]) |
|---|
|
Rows: 1 |
coll.indexOf()
Syntax |
|
||
Description |
Returns the index of the first match of a value in the given list or -1 if the value is not present. |
||
Arguments |
Name |
Type |
Description |
|
|
A list to be searched. |
|
|
|
A value to search for. |
|
Returns |
|
||
Indexing is 0-based. |
Returns -1 if the value is not present in the list. |
|
|
|
RETURN coll.indexOf(['a', 'b', 'c', 'c'], 'c')
An INTEGER representing the index of the item in the list.
| coll.indexOf(['a', 'b', 'c', 'c'], 'c') |
|---|
|
Rows: 1 |
RETURN coll.indexOf([1, 'b', false], 4.3)
The INTEGER -1 representing that the value is not found.
| coll.indexOf([1, 'b', false], 4.3) |
|---|
|
Rows: 1 |
coll.insert()
Syntax |
|
||
Description |
Returns a list with the given value inserted at the given index. |
||
Arguments |
Name |
Type |
Description |
|
|
A list to add to. |
|
|
|
The index to add the given value at. |
|
|
|
The value to add into the list. |
|
Returns |
|
||
Indexing is 0-based. |
|
|
|
If the given |
RETURN coll.insert([true, 'a', 1, 5.4], 1, false)
The original list with a new value inserted at the given index, shifting all the values following by 1.
| coll.insert([true, 'a', 1, 5.4], 1, false) |
|---|
|
Rows: 1 |
coll.max()
Syntax |
|
||
Description |
Returns the largest value present in the given list. |
||
Arguments |
Name |
Type |
Description |
|
|
A list to be searched. |
|
Returns |
|
||
|
|
The maximum is determined using Cypher®'s standard value ordering; see Equality, ordering, and comparison of value types. |
RETURN coll.max([true, 'a', 1, 5.4])
The maximum value found in the given list based on Cypher’s ordering.
| coll.max([true, 'a', 1, 5.4]) |
|---|
|
Rows: 1 |
coll.min()
Syntax |
|
||
Description |
Returns the smallest value present in the given list. |
||
Arguments |
Name |
Type |
Description |
|
|
A list to be searched. |
|
Returns |
|
||
|
|
The minimum is determined using Cypher’s standard value ordering; see Equality, ordering, and comparison of value types. |
RETURN coll.min([true, 'a', 1, 5.4])
The minimum value found in the given list based on Cypher’s ordering.
| coll.min([true, 'a', 1, 5.4]) |
|---|
|
Rows: 1 |
coll.remove()
Syntax |
|
||
Description |
Returns a list with the value at the given index removed. |
||
Arguments |
Name |
Type |
Description |
|
|
A list to remove a value from. |
|
|
|
The index of the value to be removed. |
|
Returns |
|
||
Indexing is 0-based. |
|
|
|
If the given |
RETURN coll.remove([true, 'a', 1, 5.4], 1)
The original list with the value at the given index removed and all values following shifted by 1.
| coll.remove([true, 'a', 1, 5.4], 1) |
|---|
|
Rows: 1 |
coll.sort()
Syntax |
|
||
Description |
Returns a sorted list. |
||
Arguments |
Name |
Type |
Description |
|
|
A list to be sorted. |
|
Returns |
|
||
Sorting follows Cypher’s standard value ordering; see Equality, ordering, and comparison of value types. |
|
RETURN coll.sort([true, 'a', 1, 2])
The list sorted using Cypher’s ordering in ascending order.
| coll.sort([true, 'a', 1, 2]) |
|---|
|
Rows: 1 |
keys()
Syntax |
|
||
Description |
Returns a |
||
Arguments |
Name |
Type |
Description |
|
|
A node or relationship from which the names of all properties will be returned. |
|
Returns |
|
||
|
MATCH (a) WHERE a.name = 'Alice'
RETURN keys(a)
A LIST<STRING> containing the names of all the properties on the node bound to a is returned.
| keys(a) |
|---|
|
Rows: 1 |
labels()
Syntax |
|
||
Description |
Returns a |
||
Arguments |
Name |
Type |
Description |
|
|
A node whose labels will be returned. |
|
Returns |
|
||
|
The order of the returned labels is not guaranteed when using the |
MATCH (a) WHERE a.name = 'Alice'
RETURN labels(a)
A LIST<STRING> containing all the labels of the node bound to a is returned.
| labels(a) |
|---|
|
Rows: 1 |
nodes()
Syntax |
|
||
Description |
Returns a |
||
Arguments |
Name |
Type |
Description |
|
|
A path whose nodes will be returned. |
|
Returns |
|
||
The |
|
MATCH p = (a)-->(b)-->(c)
WHERE a.name = 'Alice' AND c.name = 'Eskil'
RETURN nodes(p)
A LIST<NODE> containing all the nodes in the path p is returned.
| nodes(p) |
|---|
|
Rows: 1 |
range()
Syntax |
|
||
Description |
Returns a |
||
Arguments |
Name |
Type |
Description |
|
|
The start value of the range. |
|
|
|
The end value of the range. |
|
|
|
The size of the increment (default value: 1). |
|
Returns |
|
||
To create ranges with decreasing |
The range is inclusive for non-empty ranges, and the arithmetic progression will therefore always contain |
An empty range will be returned if the value |
RETURN range(0, 10), range(2, 18, 3), range(0, 5, -1)
Three lists of numbers in the given ranges are returned.
| range(0, 10) | range(2, 18, 3) | range(0, 5, -1) |
|---|---|---|
|
|
|
Rows: 1 |
||
reduce()
Syntax |
|
||
Description |
Runs an expression against individual elements of a |
||
Arguments |
Name |
Type |
Description |
|
|
A variable that holds the result as the |
|
|
|
The starting value of the |
|
|
|
A variable that represents each element in the |
|
|
|
The |
|
|
|
An expression that updates the |
|
Returns |
|
||
|
MATCH p = (a)-->(b)-->(c)
WHERE a.name = 'Alice' AND b.name = 'Bob' AND c.name = 'Daniel'
RETURN reduce(totalAge = 0, n IN nodes(p) | totalAge + n.age) AS reduction
The age property of all NODE values in the PATH are summed and returned as a single value.
| reduction |
|---|
|
Rows: 1 |
relationships()
Syntax |
|
||
Description |
Returns a |
||
Arguments |
Name |
Type |
Description |
|
|
The path from which all relationships will be returned. |
|
Returns |
|
||
|
MATCH p = (a)-->(b)-->(c)
WHERE a.name = 'Alice' AND c.name = 'Eskil'
RETURN relationships(p)
A LIST<RELATIONSHIP> containing all the RELATIONSHIP values in the PATH p is returned.
| relationships(p) |
|---|
|
Rows: 1 |
reverse()
Syntax |
|
||
Description |
Returns a |
||
Arguments |
Name |
Type |
Description |
|
|
The string or list to be reversed. |
|
Returns |
|
||
Any |
See also String functions → |
WITH [4923,'abc',521, null, 487] AS ids
RETURN reverse(ids)
| reverse(ids) |
|---|
|
Rows: 1 |
tail()
Syntax |
|
||
Description |
Returns all but the first element in a |
||
Arguments |
Name |
Type |
Description |
|
|
A list from which all but the first element will be returned. |
|
Returns |
|
||
MATCH (a) WHERE a.name = 'Eskil'
RETURN a.likedColors, tail(a.likedColors)
The property named likedColors and a LIST<ANY> comprising all but the first element of the likedColors property are returned.
| a.likedColors | tail(a.likedColors) |
|---|---|
|
|
Rows: 1 |
|
toBooleanList()
Syntax |
|
||
Description |
Converts a |
||
Arguments |
Name |
Type |
Description |
|
|
A list of values to be converted into a list of booleans. |
|
Returns |
|
||
Any |
Any |
If the |
If the |
The conversion for each value in |
RETURN toBooleanList(null) as noList,
toBooleanList([null, null]) as nullsInList,
toBooleanList(['a string', true, 'false', null, ['A','B']]) as mixedList
| noList | nullsInList | mixedList |
|---|---|---|
|
|
|
Rows: 1 |
||
toFloatList()
Syntax |
|
||
Description |
Converts a |
||
Arguments |
Name |
Type |
Description |
|
|
A list of values or a vector value to be converted into a list of floats. |
|
Returns |
|
||
Any |
Any |
If the |
If the |
|
The conversion for each value in |
RETURN toFloatList(null) as noList,
toFloatList([null, null]) as nullsInList,
toFloatList(['a string', 2.5, '3.14159', null, ['A','B']]) as mixedList
| noList | nullsInList | mixedList |
|---|---|---|
|
|
|
Rows: 1 |
||
toIntegerList()
Syntax |
|
||
Description |
Converts a |
||
Arguments |
Name |
Type |
Description |
|
|
A list of values or a vector value to be converted into a list of integers. |
|
Returns |
|
||
Any |
Any |
If the |
If the |
|
The conversion for each value in |
RETURN toIntegerList(null) as noList,
toIntegerList([null, null]) as nullsInList,
toIntegerList(['a string', 2, '5', null, ['A','B']]) as mixedList
| noList | nullsInList | mixedList |
|---|---|---|
|
|
|
Rows: 1 |
||
toStringList()
Syntax |
|
||
Description |
Converts a |
||
Arguments |
Name |
Type |
Description |
|
|
A list of values to be converted into a list of strings. |
|
Returns |
|
||
Any |
Any |
If the |
If the |
The conversion for each value in |
RETURN toStringList(null) as noList,
toStringList([null, null]) as nullsInList,
toStringList(['already a string', 2, date({year:1955, month:11, day:5}), null, ['A','B']]) as mixedList
| noList | nullsInList | mixedList |
|---|---|---|
|
|
|
Rows: 1 |
||