Source: https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/fe/predicates/comparison/ Documentation version: v5.3.2 # Comparison predicate The comparison predicate compares two values and returns `true` if the comparison is true, `false` if the comparison is false, and `null` if any of the values is `null`. ## Syntax diagramsource comparison_predicate comp_op ```` comparison_predicate ::= comparison_predicand comp_op comparison_predicand comp_op ::= '=' | '<>' | '<' | '>' | '<=' | '>=' ```` ## Parameters ### `comparison_predicand` A value that is compared with another value. The values to be compared must be of the same value type; otherwise, the error `NR002` is returned indicating an undefined function. ### `comp_op` The operator that is used to compare two values. The applicable operator differs depending on the value type. The following table lists the operators that can be used with each value type: | Value type | Operator | Description | Numeric value | `=`, `<>`, `<`, `>`, `<=`, `>=` | The comparison follows the mathematical rules. | String value | `=`, `<>`, `<`, `>`, `<=`, `>=` | The comparison is based on lexicographical byte-wise order. | Boolean value | `=`, `<>`, `<`, `>`, `<=`, `>=` | The comparison follows the rule that `true` is greater than `false`. | Null value | `=`, `<>`, `<`, `>`, `<=`, `>=` | Any comparison with a null value returns `null`. | Temporal instant value | `=`, `<>`, `<`, `>`, `<=`, `>=` | The comparison is based on the chronological order. | Temporal duration value | `=`, `<>`, `<`, `>`, `<=`, `>=` | The comparison is based on the duration of time. | List value | `=`, `<>` | The comparison that whether the elements of two lists are the same. It returns `true` if the two lists have the same elements in the same order, and `false` otherwise. | Set value | `=`, `<>` | The comparison that whether the elements of two sets are the same. It returns `true` if the two sets have the same elements, and `false` otherwise. | Map value | `=`, `<>` | The comparison that whether the key-value pairs of two maps are the same. It returns `true` if the two maps have the same key-value pairs, and `false` otherwise. | Record value | `=`, `<>` | The comparison that whether the field names and values of two records are the same. It returns `true` if the two records have the same fields with the same values, and `false` otherwise. | Graph element value | `=`, `<>` | The comparison that whether two graph elements are the same. It returns `true` if the two graph elements are the same, and `false` otherwise. | Path value | `=`, `<>` | The comparison that whether two paths are the same. It returns `true` if the two paths are the same, and `false` otherwise. | Spatial value | `=`, `<>` | The comparison that whether two spatial values are the same. It returns `true` if the two spatial values are the same, and `false` otherwise. ## Examples The following examples are based on the [example dataset](https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/overview/example-dataset/). ### Compare strings ```` LET l1= 'w55', l2='e34' RETURN l1 > l2 AS a ```` Return: ```` +------+ | a | +------+ | true | +------+ ```` ### Compare boolean values ```` RETURN (2>1) > (1>2) AS a, (2>1) <= (3>2) AS b ```` Return: ```` +------+------+ | a | b | +------+------+ | true | true | +------+------+ ```` ### Compare null values ```` ''' RETURN null > (1>2) AS a, null >= 1 AS b, null < "String" AS c, null = LIST[1,2,3] AS d, null < local_datetime("2012-03-04T05:06:07.0890") AS e, null <> RECORD{} AS f ''' ```` Return: ```` +------+------+------+------+------+------+ | a | b | c | d | e | f | +------+------+------+------+------+------+ | null | null | null | null | null | null | +------+------+------+------+------+------+ ```` ### Compare list values ```` LET l1= LIST[1,2,3], l2=LIST[1,2,3.5] RETURN l1 = l2 AS a ```` Return: ```` +-------+ | a | +-------+ | false | +-------+ ```` ### Compare temporal instant values ```` LET t1=local_datetime("2012-03-04T05:06:07.0890"), t2=local_datetime("2012-03-02T05:06:07.0") RETURN t1 > t2 AS a ```` Return: ```` +------+ | a | +------+ | true | +------+ ```` ### Compare temporal duration values ```` LET d1=duration({years:1, months:2}), d2=duration({years:1, months:3}) RETURN d1 < d2 AS a ```` Return: ```` +------+ | a | +------+ | true | +------+ ```` ### Compare record values ```` LET r1 = {a:1, b:true, c:"str"}, r2 = {a:1, c:"str", b:true} RETURN r1 = r2 AS a ```` Return: ```` +------+ | a | +------+ | true | +------+ ```` ### Compare graph element values ```` ''' USE movie MATCH (v1@Director)->(m1), (v2@Director)->(m2) WHERE m1.name = "Saw III" AND m2.name = "Saw IV" RETURN v1 = v2 AS a ''' ```` The preceding statement selects the directors of the movies "Saw III" and "Saw IV" and compares whether they are the same person. Return: ```` +------+ | a | +------+ | true | +------+ ```` ### Compare path values ```` ''' USE movie MATCH p1 = (m1@Movie)<-(u1@`User`), p2 = (m2@Movie)<-(u2@`User`) WHERE u1.id = u2.id RETURN p1 = p2 AS a, m1.name, m2.name LIMIT 5 ''' ```` The preceding statement selects the paths that start from the same user and end at movies, and compares whether the paths are the same. Return: ```` +-------+--------------------------------------------------------+--------------------------------------------------------+ | a | m1.name | m2.name | +-------+--------------------------------------------------------+--------------------------------------------------------+ | false | Simpsons | Pirates of the Caribbean: The Curse of the Black Pearl | | false | Simpsons | Harry Potter and the Philosopher's Stone | | false | Simpsons | Pi | | false | Pirates of the Caribbean: The Curse of the Black Pearl | Simpsons | | false | Pirates of the Caribbean: The Curse of the Black Pearl | Harry Potter and the Philosopher's Stone | +-------+--------------------------------------------------------+--------------------------------------------------------+ ```` ### Compare spatial values ```` ''' LET l1= ST_GeogFromText ('POINT (34.0522 -18.2437) '), l2=ST_GeogFromText ('POINT (34.0522 -18.2437) ') RETURN l1 = l2 AS a, l1 <> l2 AS b ''' ```` Return: ```` +------+-------+ | a | b | +------+-------+ | true | false | +------+-------+ ```` ### Compare set values ```` LET l1 = SET {1,2,3}, l2 = SET {1,2,3.5} RETURN l1 = l2 AS a, l1 <> l2 AS b ```` Return: ```` +-------+------+ | a | b | +-------+------+ | false | true | +-------+------+ ```` ### Compare map values ```` LET m1 = MAP {'a':1, 'b':2}, m2 = MAP {'b':2, 'a':1, 'b': 3} RETURN m1 = m2 AS a, m1 <> m2 AS b ```` Return: ```` +------+-------+ | a | b | +------+-------+ | true | false | +------+-------+ ````