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:Adminstrator {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)
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 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 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 |
||