Predicate functions¶
Predicate functions return true
or false
. They are most commonly used in WHERE
clauses.
NebulaGraph supports the following predicate functions:
Functions | Description |
---|---|
exists() | Returns true if the specified property exists in the vertex, edge or map. Otherwise, returns false . |
any() | Returns true if the specified predicate holds for at least one element in the given list. Otherwise, returns false . |
all() | Returns true if the specified predicate holds for all elements in the given list. Otherwise, returns false . |
none() | Returns true if the specified predicate holds for no element in the given list. Otherwise, returns false . |
single() | Returns true if the specified predicate holds for exactly one of the elements in the given list. Otherwise, returns false . |
Note
NULL is returned if the list is NULL or all of its elements are NULL.
Compatibility
In openCypher, only function exists()
is defined and specified. The other functions are implement-dependent.
Syntax¶
<predicate>(<variable> IN <list> WHERE <condition>)
Examples¶
nebula> RETURN any(n IN [1, 2, 3, 4, 5, NULL] \
WHERE n > 2) AS r;
+------+
| r |
+------+
| true |
+------+
nebula> RETURN single(n IN range(1, 5) \
WHERE n == 3) AS r;
+------+
| r |
+------+
| true |
+------+
nebula> RETURN none(n IN range(1, 3) \
WHERE n == 0) AS r;
+------+
| r |
+------+
| true |
+------+
nebula> WITH [1, 2, 3, 4, 5, NULL] AS a \
RETURN any(n IN a WHERE n > 2);
+-------------------------+
| any(n IN a WHERE (n>2)) |
+-------------------------+
| true |
+-------------------------+
nebula> MATCH p = (n:player{name:"LeBron James"})<-[:follow]-(m) \
RETURN nodes(p)[0].name AS n1, nodes(p)[1].name AS n2, \
all(n IN nodes(p) WHERE n.name NOT STARTS WITH "D") AS b;
+----------------+-------------------+-------+
| n1 | n2 | b |
+----------------+-------------------+-------+
| "LeBron James" | "Danny Green" | false |
| "LeBron James" | "Dejounte Murray" | false |
| "LeBron James" | "Chris Paul" | true |
| "LeBron James" | "Kyrie Irving" | true |
| "LeBron James" | "Carmelo Anthony" | true |
| "LeBron James" | "Dwyane Wade" | false |
+----------------+-------------------+-------+
nebula> MATCH p = (n:player{name:"LeBron James"})-[:follow]->(m) \
RETURN single(n IN nodes(p) WHERE n.age > 40) AS b;
+------+
| b |
+------+
| true |
+------+
nebula> MATCH (n:player) \
RETURN exists(n.player.id), n IS NOT NULL;
+--------------+---------------+
| exists(n.id) | n IS NOT NULL |
+--------------+---------------+
| false | true |
...
nebula> MATCH (n:player) \
WHERE exists(n['name']) RETURN n;
+-------------------------------------------------------------------------------------------------------------+
| n |
+-------------------------------------------------------------------------------------------------------------+
| ("Grant Hill" :player{age: 46, name: "Grant Hill"}) |
| ("Marc Gasol" :player{age: 34, name: "Marc Gasol"}) |
+-------------------------------------------------------------------------------------------------------------+
...
Last update:
February 1, 2023