Scalar functions
Scalar functions return a single value.
The
|
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 |
elementId()
The function elementId()
returns a node or relationship identifier, unique within a specific transaction and DBMS.
There are important considerations to bear in mind when using elementId()
:
-
Every node and relationship is guaranteed an element ID. This ID is unique among both nodes and relationships across all databases in the same DBMS within the scope of a single transaction. However, no guarantees are given regarding the order of the returned ID values or the length of the ID string values. Outside of the scope of a single transaction, no guarantees are given about the mapping between ID values and elements.
-
Neo4j reuses its internal IDs when nodes and relationships are deleted. This means that applications using, and relying on internal Neo4j IDs, are brittle or at risk of making mistakes. It is therefore recommended to rather use application-generated IDs.
Syntax:
elementId(expression)
Returns:
A String. |
Arguments:
Name | Description |
---|---|
|
An expression that returns a node or a relationship. |
Considerations:
|
|
MATCH (a)
RETURN elementId(a)
The node identifier for each of the nodes is returned.
elementId(a) |
---|
|
|
|
|
|
Rows: 5 |
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() Deprecated
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.
The function |
Neo4j implements the ID so that: Node Every node in a database has an identifier. The identifier for a node is guaranteed to be unique among other nodes' identifiers in the same database, within the scope of a single transaction. Relationship Every relationship in a database has an identifier. The identifier for a relationship is guaranteed to be unique among other relationships' identifiers in the same database, within the scope of a single transaction. |
On a composite database, the When called in database-specific subqueries, the resulting id value for a node or relationship is local to that database. The local id for nodes or relationships from different databases may be the same. When called from the root context of a query, the resulting value is an extended id for the node or relationship. The extended id is likely different from the local id for the same node or relationship. |
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 comprehension
This is the same function size()
as described above, but you pass in a pattern comprehension.
The function size will then calculate on a list of paths.
Syntax:
size(pattern comprehension)
Arguments:
Name | Description |
---|---|
|
A pattern comprehension that returns a list. |
MATCH (a)
WHERE a.name = 'Alice'
RETURN size([p=(a)-->()-->() | p]) 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 |
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 |
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 |
Was this page helpful?