Scalar functions
Functions:
The
|
N0 [ label = "{Developer|name = \'Alice\'\lage = 38\leyes = \'brown\'\l}" ] N0 -> N2 [ color = "#2e3436" fontcolor = "#2e3436" label = "KNOWS\n" ] N0 -> N1 [ color = "#2e3436" fontcolor = "#2e3436" label = "KNOWS\n" ] N1 [ label = "name = \'Bob\'\lage = 25\leyes = \'blue\'\l" ] N1 -> N3 [ color = "#2e3436" fontcolor = "#2e3436" label = "KNOWS\n" ] N1 -> N4 [ color = "#4e9a06" fontcolor = "#4e9a06" label = "MARRIED\n" ] N2 [ label = "name = \'Charlie\'\lage = 53\leyes = \'green\'\l" ] N2 -> N3 [ color = "#2e3436" fontcolor = "#2e3436" label = "KNOWS\n" ] N3 [ label = "name = \'Daniel\'\lage = 54\leyes = \'brown\'\l" ] N4 [ label = "eyes = \'blue\'\lliked_colors = \[\'pink\', \'yellow\', \'black\'\]\lname = \'Eskil\'\lage = 41\l" ]
coalesce()
The function coalesce()
returns the first non-null
value in the given list of expressions.
Syntax: coalesce(expression [, expression]*)
Returns:
The type of the value returned will be that of the first non- |
Arguments:
Name | Description |
---|---|
|
An expression that may return |
Considerations:
|
MATCH (a)
WHERE a.name = 'Alice'
RETURN coalesce(a.hairColor, a.eyes)
coalesce(a.hairColor, a.eyes) |
---|
|
Rows: 1 |
endNode()
The function endNode()
returns the end node of a relationship.
Syntax: endNode(relationship)
Returns:
A Node. |
Arguments:
Name | Description |
---|---|
|
An expression that returns a relationship. |
Considerations:
|
MATCH (x:Developer)-[r]-()
RETURN endNode(r)
endNode(r) |
---|
|
|
Rows: 2 |
head()
The function head()
returns the first element in a list.
Syntax: head(expression)
Returns:
The type of the value returned will be that of the first element of the list. |
Arguments:
Name | Description |
---|---|
|
An expression that returns a list. |
Considerations:
|
|
If the first element in |
MATCH (a)
WHERE a.name = 'Eskil'
RETURN a.liked_colors, head(a.liked_colors)
The first element in the list is returned.
a.liked_colors | head(a.liked_colors) |
---|---|
|
|
Rows: 1 |
id()
The function id()
returns a node or a relationship identifier, unique by an object type and a database.
Therefore, it is perfectly allowable for id()
to return the same value for both nodes and relationships in the same database.
For examples on how to get a node and a relationship by ID, see Get node or relationship by id.
Neo4j implements the id so that:
|
Syntax: id(expression)
Returns:
An Integer. |
Arguments:
Name | Description |
---|---|
|
An expression that returns a node or a relationship. |
Considerations:
|
MATCH (a)
RETURN id(a)
The node identifier for each of the nodes is returned.
id(a) |
---|
|
|
|
|
|
Rows: 5 |
last()
The function last()
returns the last element in a list.
Syntax: last(expression)
Returns:
The type of the value returned will be that of the last element of the list. |
Arguments:
Name | Description |
---|---|
|
An expression that returns a list. |
Considerations:
|
|
If the last element in |
MATCH (a)
WHERE a.name = 'Eskil'
RETURN a.liked_colors, last(a.liked_colors)
The last element in the list is returned.
a.liked_colors | last(a.liked_colors) |
---|---|
|
|
Rows: 1 |
length()
The function length()
returns the length of a path.
Syntax: length(path)
Returns:
An Integer. |
Arguments:
Name | Description |
---|---|
|
An expression that returns a path. |
Considerations:
|
MATCH p = (a)-->(b)-->(c)
WHERE a.name = 'Alice'
RETURN length(p)
The length of the path p
is returned.
length(p) |
---|
|
|
|
Rows: 3 |
properties()
The function properties()
returns a map containing all the properties; the function can be utilized for a relationship or a node.
If the argument is already a map, it is returned unchanged.
Syntax: properties(expression)
Returns:
A Map. |
Arguments:
Name | Description |
---|---|
|
An expression that returns a relationship, a node, or a map. |
Considerations:
|
CREATE (p:Person {name: 'Stefan', city: 'Berlin'})
RETURN properties(p)
properties(p) |
---|
|
Rows: 1 |
randomUUID()
The function randomUUID()
returns a randomly-generated Universally Unique Identifier (UUID), also known as a Globally Unique Identifier (GUID).
This is a 128-bit value with strong guarantees of uniqueness.
Syntax: randomUUID()
Returns:
A String. |
RETURN randomUUID() AS uuid
uuid |
---|
|
Rows: 1 |
A randomly-generated UUID is returned.
size()
The function size()
returns the number of elements in a list.
Syntax: size(list)
Returns:
An Integer. |
Arguments:
Name | Description |
---|---|
|
An expression that returns a list. |
Considerations:
|
RETURN size(['Alice', 'Bob'])
size(['Alice', 'Bob']) |
---|
|
Rows: 1 |
The number of elements in the list is returned.
size() applied to pattern expression
This is the same function size()
as described above, but you pass in a pattern expression, instead of a list.
The function size will then calculate on a list of paths.
Syntax: size(pattern expression)
Arguments:
Name | Description |
---|---|
|
A pattern expression that returns a list. |
MATCH (a)
WHERE a.name = 'Alice'
RETURN size((a)-->()-->()) AS fof
fof |
---|
|
Rows: 1 |
The number of paths matching the pattern expression is returned. (The size of the list of paths).
size() applied to string
The function size()
returns the number of Unicode characters in a string.
Syntax: size(string)
Returns:
An Integer. |
Arguments:
Name | Description |
---|---|
|
An expression that returns a string value. |
Considerations:
|
MATCH (a)
WHERE size(a.name) > 6
RETURN size(a.name)
size(a.name) |
---|
|
Rows: 1 |
The number of characters in the string 'Charlie'
is returned.
startNode()
The function startNode()
returns the start node of a relationship.
Syntax: startNode(relationship)
Returns:
A Node. |
Arguments:
Name | Description |
---|---|
|
An expression that returns a relationship. |
Considerations:
|
MATCH (x:Developer)-[r]-()
RETURN startNode(r)
startNode(r) |
---|
|
|
Rows: 2 |
timestamp()
The function timestamp()
returns the difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC.
It is the equivalent of |
Syntax: timestamp()
Returns:
An Integer. |
Considerations:
|
RETURN timestamp()
The time in milliseconds is returned.
timestamp() |
---|
|
Rows: 1 |
toBoolean()
The function toBoolean()
converts a string, integer or boolean value to a boolean value.
Syntax: toBoolean(expression)
Returns:
A Boolean. |
Arguments:
Name | Description |
---|---|
|
An expression that returns a boolean, string or integer value. |
Considerations:
|
If |
If the parsing fails, |
If |
This function will return an error if provided with an expression that is not a string, integer or boolean value. |
RETURN toBoolean('true'), toBoolean('not a boolean'), toBoolean(0)
toBoolean('true') | toBoolean('not a boolean') | toBoolean(0) |
---|---|---|
|
|
|
Rows: 1 |
toBooleanOrNull()
The function toBooleanOrNull()
converts a string, integer or boolean value to a boolean value. For any other input value, null
will be returned.
Syntax: toBooleanOrNull(expression)
Returns:
A Boolean or |
Arguments:
Name | Description |
---|---|
|
Any expression that returns a value. |
Considerations:
|
If |
If the parsing fails, |
If |
If the |
RETURN toBooleanOrNull('true'), toBooleanOrNull('not a boolean'), toBooleanOrNull(0), toBooleanOrNull(1.5)
toBooleanOrNull('true') | toBooleanOrNull('not a boolean') | toBooleanOrNull(0) | toBooleanOrNull(1.5) |
---|---|---|---|
|
|
|
|
Rows: 1 |
toFloat()
The function toFloat()
converts an integer, floating point or a string value to a floating point number.
Syntax: toFloat(expression)
Returns:
A Float. |
Arguments:
Name | Description |
---|---|
|
An expression that returns a numeric or a string value. |
Considerations:
|
If |
If the parsing fails, |
This function will return an error if provided with an expression that is not an integer, floating point or a string value. |
RETURN toFloat('11.5'), toFloat('not a number')
toFloat('11.5') | toFloat('not a number') |
---|---|
|
|
Rows: 1 |
toFloatOrNull()
The function toFloatOrNull()
converts an integer, floating point or a string value to a floating point number. For any other input value, null
will be returned.
Syntax: toFloatOrNull(expression)
Returns:
A Float or |
Arguments:
Name | Description |
---|---|
|
Any expression that returns a value. |
Considerations:
|
If |
If the parsing fails, |
If the |
RETURN toFloatOrNull('11.5'), toFloatOrNull('not a number'), toFloatOrNull(true)
toFloatOrNull('11.5') | toFloatOrNull('not a number') | toFloatOrNull(true) |
---|---|---|
|
|
|
Rows: 1 |
toInteger()
The function toInteger()
converts a boolean, integer, floating point or a string value to an integer value.
Syntax: toInteger(expression)
Returns:
An Integer. |
Arguments:
Name | Description |
---|---|
|
An expression that returns a boolean, numeric or a string value. |
Considerations:
|
If |
If the parsing fails, |
If |
This function will return an error if provided with an expression that is not a boolean, floating point, integer or a string value. |
RETURN toInteger('42'), toInteger('not a number'), toInteger(true)
toInteger('42') | toInteger('not a number') | toInteger(true) |
---|---|---|
|
|
|
Rows: 1 |
toIntegerOrNull()
The function toIntegerOrNull()
converts a boolean, integer, floating point or a string value to an integer value. For any other input value, null
will be returned.
Syntax: toIntegerOrNull(expression)
Returns:
An Integer or |
Arguments:
Name | Description |
---|---|
|
Any expression that returns a value. |
Considerations:
|
If |
If the parsing fails, |
If |
If the |
RETURN toIntegerOrNull('42'), toIntegerOrNull('not a number'), toIntegerOrNull(true), toIntegerOrNull(['A', 'B', 'C'])
toIntegerOrNull('42') | toIntegerOrNull('not a number') | toIntegerOrNull(true) | toIntegerOrNull(['A', 'B', 'C']) |
---|---|---|---|
|
|
|
|
Rows: 1 |
type()
The function type()
returns the string representation of the relationship type.
Syntax: type(relationship)
Returns:
A String. |
Arguments:
Name | Description |
---|---|
|
An expression that returns a relationship. |
Considerations:
|
MATCH (n)-[r]->()
WHERE n.name = 'Alice'
RETURN type(r)
The relationship type of r
is returned.
type(r) |
---|
|
|
Rows: 2 |