A predicate specifies a condition that can be evaluated to give a boolean value (true or false).
Category | Predicates |
|---|---|
| Comparison Predicates | =, <> (or !=), >, <, >=, <=, =~ (or REGEXP), BETWEEN |
| Exists Predicate | EXISTS |
| Null Predicates | IS NULL, IS NOT NULL |
| Labeled Predicates | IS LABELED, IS NOT LABELED, : |
| Value Type Predicates | IS TYPED, IS NOT TYPED |
Compares two values or expressions and returns true or false. GQL supports the following comparison operators:
=<> (or !=)><>=<==~ (or REGEXP)BETWEEN ... AND, NOT BETWEEN ... ANDThe >, <, >=, and <= can be used only with numeric, textual, temporal, boolean, and null values.
GQLMATCH (n:Paper) WHERE n.score BETWEEN 6 AND 8 // equivalent to: n.score >= 6 AND n.score <= 8 RETURN n.title, n.score
GQLMATCH (n:Paper) WHERE n.score NOT BETWEEN 6 AND 8 // equivalent to: n.score < 6 OR n.score > 8 RETURN n.title, n.score
GQLLET email = "[email protected]" RETURN email =~ "[a-zA-Z0-9_.-]+@[a-zA-Z0-9]+\.(com|cn)" // true
GQLLET email = "[email protected]" RETURN email REGEXP "[a-zA-Z0-9_.-]+@[a-zA-Z0-9]+\.(com|cn)" // true
GQLRETURN 30.1 > 30 // true
The first differing character (from left to right) determines the result of the comparison. The characters are compared based on their Unicode values.
GQLRETURN "campus" < "camera" // false
This query returns false because the first differing character, p, has a higher Unicode value than e (Unicode of p is 112, while e is 101).
GQLLET email = "[email protected]" RETURN email =~ "[a-zA-Z0-9_.-]+@[a-zA-Z0-9]+\.(com|cn)" // true
Temporal values are treated like numeric values, as time is measured in units such as seconds, hours, days, and years. In GQL, the comparison between two temporal values is based on their duration—the difference between the two points in time. If the duration is 0, the values are equal; if negative, the left value is smaller; otherwise, the left value is greater.
GQLRETURN date("1897-10-01") < date("1987-10-02") // true
Two lists are considered equal if they contain the same elements in the exact same order.
GQLRETURN [1,2,3] = [1,2,3], // true [] = [], // true [1,2,3] = [1,3,2] // false
Two records are considered equal if they have the same fields with identical values.
GQLRETURN {a:1, b:2} = {a:1, b:2}, // true {a:1, b:2} = {a:2, b:2}, // false {a:1} = {b:1} // false
Two nodes or edges are equal if they have the same _id.
GQLMATCH (n1 {_id: "P1"}), (n2 {_id: "P1"}), (n3 {_id: "P3"}) RETURN n1 = n2, n1=n3 // true, false
Paths are similar to lists, as they consist of sequences of nodes and edges.
Comparisons between different type categories (e.g., string vs. number, boolean vs. integer) are not supported. Values must be of the same type or within the same category (e.g., integer and float) to be compared. Use explicit conversion functions like cast() when needed.
GQLRETURN "42" > 10 // cannot compare STRING with INTEGER
The EXISTS predicate evaluates whether a specified subquery returns any results. If it finds matching data, the predicate evaluates to true; otherwise, it evaluates to false.
Syntax<exists predicate> ::= "EXISTS" "{" <query> "}"
The <query> must contain at least one statement (e.g., MATCH). A RETURN statement is not required as EXISTS only checks whether the subquery produces any rows.
Checks whether any path originating from node P1 exists in the graph:
GQLRETURN EXISTS { MATCH ({_id: "P1"})->() }
EXISTS can also be used in the WHERE clause of a MATCH statement. Variables from the outer query are accessible inside the subquery:
GQLMATCH (n:Paper) WHERE n.score > 7 AND EXISTS { MATCH (n)<-[:Cites]-() } RETURN n.title
Specifies a test for a null value. GQL supports the following null predicates:
IS NULL (or IS UNKNOWN)IS NOT NULL (or IS NOT UNKNOWN)GQLMATCH (n:Paper) WHERE n.publisher IS NOT NULL RETURN n
Determines whether a graph element satisfies a label expression. GQL supports the following labeled predicates:
IS LABELEDIS NOT LABELED:GQLMATCH (n) WHERE n IS NOT LABELED Paper RETURN n
GQLMATCH (n) WHERE n:Paper RETURN n
Determines whether a value conforms to a specific type. GQL supports the following value type predicates:
IS TYPEDIS NOT TYPEDSupported value type keywords: INT/INTEGER, FLOAT, DOUBLE, BOOL/BOOLEAN, STRING, TEXT, LIST, MAP, DATE, TIME, DATETIME, DURATION, PATH, NODE, EDGE, NULL.
GQLRETURN "hello" IS TYPED STRING, 42 IS TYPED INT, 3.14 IS TYPED FLOAT, [1,2] IS TYPED LIST, "hello" IS NOT TYPED INT