Predicate functions
all()
The function all()
returns true
if the predicate holds for all elements in the given list.
null
is returned if the list is null
or all of its elements are null
.
Syntax:
all(variable IN list WHERE predicate)
Returns:
A Boolean. |
Arguments:
Name | Description |
---|---|
|
An expression that returns a list. A single element cannot be explicitly passed as a literal in the cypher statement. However, an implicit conversion will happen for single elements when passing node properties during cypher execution. |
|
A variable that can be used from within the predicate. |
|
A predicate that is tested against all items in the list. |
MATCH p = (a)-[*1..3]->(b)
WHERE
a.name = 'Alice'
AND b.name = 'Daniel'
AND all(x IN nodes(p) WHERE x.age > 30)
RETURN p
All nodes in the returned paths will have a property age
with a value larger than 30
.
p |
---|
|
Rows: 1 |
any()
The function any()
returns true
if the predicate holds for at least one element in the given list.
null
is returned if the list is null
or all of its elements are null
.
Syntax:
any(variable IN list WHERE predicate)
Returns:
A Boolean. |
Arguments:
Name | Description |
---|---|
|
An expression that returns a list. A single element cannot be explicitly passed as a literal in the cypher statement. However, an implicit conversion will happen for single elements when passing node properties during cypher execution. |
|
A variable that can be used from within the predicate. |
|
A predicate that is tested against all items in the list. |
MATCH (n)
WHERE any(color IN n.liked_colors WHERE color = 'yellow')
RETURN n
The query returns nodes with the property liked_colors
(as a list), where at least one element has the value 'yellow'
.
n |
---|
|
Rows: 1 |
exists()
The function exists()
returns true
if a match for the given pattern exists in the graph, or if the specified property exists in the node, relationship or map.
null
is returned if the input argument is null
.
Syntax:
exists(pattern-or-property)
Returns:
A Boolean. |
Arguments:
Name | Description |
---|---|
|
A pattern or a property (in the form 'variable.prop'). |
MATCH (n)
WHERE n.name IS NOT NULL
RETURN
n.name AS name,
exists((n)-[:MARRIED]->()) AS is_married
The names of all nodes with the name
property are returned, along with a boolean (true
or false
) indicating if they are married.
name | is_married |
---|---|
|
|
|
|
|
|
|
|
|
|
Rows: 5 |
MATCH
(a),
(b)
WHERE
exists(a.name)
AND NOT exists(b.name)
OPTIONAL MATCH (c:DoesNotExist)
RETURN
a.name AS a_name,
b.name AS b_name,
exists(b.name) AS b_has_name,
c.name AS c_name,
exists(c.name) AS c_has_name
ORDER BY a_name, b_name, c_name
LIMIT 1
Three nodes are returned: one with a property name
, one without a property name
, and one that does not exist (e.g., is null
).
This query exemplifies the behavior of exists()
when operating on null
nodes.
a_name | b_name | b_has_name | c_name | c_has_name |
---|---|---|---|---|
|
|
|
|
|
Rows: 1 |
Note that the |
isEmpty()
The function isEmpty()
returns true
if the given list or map contains no elements or if the given string contains no characters.
Syntax:
isEmpty(list)
Returns:
A Boolean. |
Arguments:
Name | Description |
---|---|
|
An expression that returns a list. |
MATCH (n)
WHERE NOT isEmpty(n.liked_colors)
RETURN n
The nodes with the property liked_colors
being non-empty are returned.
n |
---|
|
|
Rows: 2 |
Syntax:
isEmpty(map)
Returns:
A Boolean. |
Arguments:
Name | Description |
---|---|
|
An expression that returns a map. |
MATCH (n)
WHERE isEmpty(properties(n))
RETURN n
Nodes that does not have any properties are returned.
n |
---|
|
Rows: 1 |
Syntax:
isEmpty(string)
Returns:
A Boolean. |
Arguments:
Name | Description |
---|---|
|
An expression that returns a string. |
MATCH (n)
WHERE isEmpty(n.eyes)
RETURN n.age AS age
The age are returned for each node that has a property eyes
where the value evaulates to be empty (empty string).
age |
---|
|
Rows: 1 |
The function |
none()
The function none()
returns true
if the predicate does not hold for any element in the given list.
null
is returned if the list is null
or all of its elements are null
.
Syntax:
none(variable IN list WHERE predicate)
Returns:
A Boolean. |
Arguments:
Name | Description |
---|---|
|
An expression that returns a list. A single element cannot be explicitly passed as a literal in the cypher statement. However, an implicit conversion will happen for single elements when passing node properties during cypher execution. |
|
A variable that can be used from within the predicate. |
|
A predicate that is tested against all items in the list. |
MATCH p = (n)-[*1..3]->(b)
WHERE
n.name = 'Alice'
AND none(x IN nodes(p) WHERE x.age = 25)
RETURN p
No node in the returned paths has a property age
with the value 25
.
p |
---|
|
|
Rows: 2 |
single()
The function single()
returns true
if the predicate holds for exactly one of the elements in the given list.
null
is returned if the list is null
or all of its elements are null
.
Syntax:
single(variable IN list WHERE predicate)
Returns:
A Boolean. |
Arguments:
Name | Description |
---|---|
|
An expression that returns a list. |
|
A variable that can be used from within the predicate. |
|
A predicate that is tested against all items in the list. |
MATCH p = (n)-->(b)
WHERE
n.name = 'Alice'
AND single(var IN nodes(p) WHERE var.eyes = 'blue')
RETURN p
In every returned path there is exactly one node that has a property eyes
with the value 'blue'
.
p |
---|
|
Rows: 1 |