Scalar functions
Scalar functions return a single value.
The
|
char_length()
This feature was introduced in Neo4j 5.13.
The function char_length()
returns the number of Unicode characters in a STRING
.
This function is an alias of the size()
function.
Syntax:
char_length(string)
Returns:
|
Arguments:
Name | Description |
---|---|
|
An expression that returns a |
Considerations:
|
RETURN char_length('Alice')
char_length('Alice') |
---|
|
Rows: 1 |
The number of Unicode characters in the string is returned.
character_length()
This feature was introduced in Neo4j 5.13.
The function character_length()
returns the number of Unicode characters in a STRING
.
This function is an alias of the size()
function.
Syntax:
character_length(string)
Returns:
|
Arguments:
Name | Description |
---|---|
|
An expression that returns a |
Considerations:
|
RETURN character_length('Alice')
character_length('Alice') |
---|
|
Rows: 1 |
The number of Unicode characters in the string is returned.
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:
|
Arguments:
Name | Description |
---|---|
|
An expression that returns a |
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:
|
Arguments:
Name | Description |
---|---|
|
An expression that returns a |
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.
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:
|
Arguments:
Name | Description |
---|---|
|
An expression that returns a |
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:
|
Arguments:
Name | Description |
---|---|
|
An expression that returns a |
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:
|
Arguments:
Name | Description |
---|---|
|
An expression that returns a |
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:
|
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:
|
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<PATH>
.
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:
|
Arguments:
Name | Description |
---|---|
|
An expression that returns a |
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:
|
Arguments:
Name | Description |
---|---|
|
An expression that returns a |
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:
|
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:
|
Arguments:
Name | Description |
---|---|
|
An expression that returns a |
Considerations:
|
If |
If the parsing fails, |
If |
This function will return an error if provided with an expression that is not a |
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:
|
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
, FLOAT
or a STRING
value to a FLOAT
.
Syntax:
toFloat(expression)
Returns:
|
Arguments:
Name | Description |
---|---|
|
An expression that returns an |
Considerations:
|
If |
If the parsing fails, |
This function will return an error if provided with an expression that is not an |
RETURN toFloat('11.5'), toFloat('not a number')
toFloat('11.5') | toFloat('not a number') |
---|---|
|
|
Rows: 1 |
toFloatOrNull()
The function toFloatOrNull()
converts an INTEGER
, FLOAT
or a STRING
value to a FLOAT
.
For any other input value, null
will be returned.
Syntax:
toFloatOrNull(expression)
Returns:
|
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
, FLOAT
or a STRING
value to an INTEGER
value.
Syntax:
toInteger(expression)
Returns:
|
Arguments:
Name | Description |
---|---|
|
An expression that returns a |
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
, FLOAT
or a STRING
value to an INTEGER
value. For any other input value, null
will be returned.
Syntax:
toIntegerOrNull(expression)
Returns:
|
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:
|
Arguments:
Name | Description |
---|---|
|
An expression that returns a |
Considerations:
|
MATCH (n)-[r]->()
WHERE n.name = 'Alice'
RETURN type(r)
The relationship type of r
is returned.
type(r) |
---|
|
|
Rows: 2 |
valueType()
This feature was introduced in Neo4j 5.13.
The function valueType()
returns a STRING
representation of the most precise value type that the given expression evaluates to.
The output is deterministic and makes use of Type Normalization.
Syntax:
valueType(expression)
Returns:
|
Arguments:
Name | Description |
---|---|
|
Any expression that returns a value. |
Considerations:
It is possible that future releases of Cypher® will include updates to the current type system.
This can include the introduction of new types and subtypes of already supported types.
If a new type is introduced, it will be returned by the valueType()
function as soon as it is released.
However, if a more precise subtype of a previously supported type is introduced, it would be considered a breaking change.
As a result, any new subtypes introduced after the release of Neo4j 5.13 will not be returned by the valueType()
function until the following major release (Neo4j 6.0).
For example, the function currently returns "FLOAT"
, but if a more specific FLOAT
type was added, e.g. FLOAT32
, this would be considered more specific and not be returned until Neo4j 6.0.
As a result,"FLOAT"
would continue to be returned for any FLOAT32
values until the release of Neo4j 6.0.
With this in mind, the below list contains all supported types (as of Neo4j 5.13) displayed by the valueType()
function until the release of Neo4j 6.0:
-
Predefined types
-
NOTHING
-
NULL
-
BOOLEAN
-
STRING
-
INTEGER
-
FLOAT
-
DATE
-
LOCAL TIME
-
ZONED TIME
-
LOCAL DATETIME
-
ZONED DATETIME
-
DURATION
-
POINT
-
NODE
-
RELATIONSHIP
-
-
Constructed types
-
MAP
-
LIST<INNER_TYPE>
(ordered by the inner type) -
PATH
-
-
Dynamic union types
-
INNER_TYPE_1 \| INNER_TYPE_2…
(ordered by specific rules for closed dynamic union type) -
ANY
-
This should be taken into account when relying on the output of the valueType()
function.
See the type predicate expression for an alternative way of testing type values.
UNWIND ["abc", 1, 2.0, true, [date()]] AS value
RETURN valueType(value) AS result
result |
---|
|
|
|
|
|
Rows: 5 |
Was this page helpful?