Scalar Functions¶
Introduction¶
Scalar functions return a single value.
The following graph is used in the examples below:
Run this Cypher in Quine to create the sample graph.
CREATE
(alice:Person:Developer {name:'Alice', age: 38, eyes: 'brown'}),
(bob {name: 'Bob', surname: 'Smith', age: 25, eyes: 'blue'}),
(charlie {name: 'Charlie', surname: 'Brown', age: 53, eyes: 'green'}),
(daniel {name: 'Daniel', age: 54, eyes: 'brown'}),
(eskil {name: 'Eskil', age: 41, eyes: 'blue', array: ['one', 'two', 'three']}),
(alice)-[:KNOWS]->(bob),
(alice)-[:KNOWS]->(charlie),
(bob)-[:KNOWS]->(daniel),
(charlie)-[:KNOWS]->(daniel),
(bob)-[:MARRIED]->(eskil)
Note
Be sure to submit the example queries below as a text query using Shift+Enter.
coalesce()
¶
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-null expression.
Arguments:
Name | Description |
---|---|
expression | An expression which may return null. |
Considerations: `null`` will be returned if all the arguments are null.
Sample:
MATCH (a)
WHERE a.name = 'Alice'
RETURN coalesce(a.hairColor, a.eyes)
{
"columns": [
"coalesce(a.hairColor, a.eyes)"
],
"results": [
[
"brown"
]
]
}
endNode()
¶
endNode()
returns the end node of a relationship.
Syntax: endNode(relationship)
Returns: A Node.
Arguments:
Name | Description |
---|---|
relationship | An expression that returns a relationship. |
Considerations: endNode(null)
returns null
.
Example:
MATCH (x:Developer)-[r]-()
RETURN endNode(r)
{
"columns": [
"endNode(r)"
],
"results": [
[
{
"id": "00c43b90-63d2-4d43-a030-6621facdda18",
"labels": [],
"properties": {
"age": 53,
"eyes": "green",
"name": "Charlie",
"surname": "Brown"
}
}
],
[
{
"id": "8d76cbd3-e386-4cbe-80ac-3f488fac9fc9",
"labels": [],
"properties": {
"age": 25,
"eyes": "blue",
"name": "Bob",
"surname": "Smith"
}
}
]
]
}
head()
¶
head()
returns the first element in a list.
Syntax: head(list)
Returns: The type of the value returned will be that of the first element of list.
Arguments:
Name | Description |
---|---|
list | An expression that returns a list. |
Considerations: head(null)
returns null. If the first element in list is null, head(list) will return null.
Example:
MATCH (a)
WHERE a.name = 'Eskil'
RETURN a.array, head(a.array)
The first element in the list is returned.
{
"columns": [
"a.array",
"head(a.array)"
],
"results": [
[
[
"one",
"two",
"three"
],
"one"
]
]
}
id()
¶
id()
returns the id of a relationship or node.
Syntax: id(expression)
Returns: A Quine ID.
Arguments:
Name | Description |
---|---|
expression | An expression that returns a node or a relationship. |
Considerations: id(null)
returns null
.
Example:
MATCH (a)
RETURN id(a)
The node id for each of the nodes is returned.
{
"columns": [
"id(a)"
],
"results": [
[
"f21e0f55-9c40-44ae-8904-18ef5d74231d"
]
]
}
last()
¶
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 list.
Arguments:
Name | Description |
---|---|
list | An expression that returns a list. |
Considerations: last(null)
returns null
. If the last element in list is null, last(list) will return null.
Example:
MATCH (a)
WHERE a.name = 'Eskil'
RETURN a.array, last(a.array)
The last element in the list is returned.
{
"columns": [
"a.array",
"last(a.array)"
],
"results": [
[
[
"one",
"two",
"three"
],
"three"
]
]
}