Skip to content

Comparison operators

Name Description
= Assign a value
/ Division operator
== Equal operator
!=, <> Not equal operator
< Less than operator
<= Less than or equal operator
- Minus operator
% Modulo operator
+ Addition operator
* Multiplication operator
- Change the sign of the argument
IS NULL NULL check
IS NOT NULL not NULL check

Comparison operations result in a value of true and false.

Note

Comparability between values of different types is often undefined. The result could be NULL or others.

OpenCypher compatibility

Comparing with NULL is different from openCypher. The behavior may change. IS [NOT] NULL is often used with OPTIONAL MATCH. But OPTIONAL MATCH is not support in nGQL.

  • ==

Equal. String comparisons are case-sensitive. Values of different types are not equal.

Note

The equality operator is == in nGQL and is = in openCypher.

nebula>  RETURN 'A' == 'a', toUpper('A') == toUpper('a'), toLower('A') == toLower('a')
+------------+------------------------------+------------------------------+
| ("A"=="a") | (toUpper("A")==toUpper("a")) | (toLower("A")==toLower("a")) |
+------------+------------------------------+------------------------------+
| false      | true                         | true                         |
+------------+------------------------------+------------------------------+

nebula> RETURN '2' == 2, toInteger('2') == 2;
+----------+---------------------+
| ("2"==2) | (toInteger("2")==2) |
+----------+---------------------+
| false    | true                |
+----------+---------------------+
  • >

Greater than:

nebula> RETURN 3 > 2;
+-------+
| (3>2) |
+-------+
| true  |
+-------+

nebula>  WITH 4 AS one, 3 AS two RETURN one > two AS result;
+--------+
| result |
+--------+
| true   |
+--------+
  • >=

Greater than or equal to:

nebula>  RETURN 2 >= "2", 2 >= 2
+----------+--------+
| (2>="2") | (2>=2) |
+----------+--------+
| __NULL__ | true   |
+----------+--------+
  • <

Less than:

nebula> YIELD 2.0 < 1.9;
+---------+
| (2<1.9) |
+---------+
| false   |
+---------+
  • <=

Less than or equal to:

nebula> YIELD 0.11 <= 0.11;
+--------------+
| (0.11<=0.11) |
+--------------+
| true         |
+--------------+
  • !=

Not equal:

nebula> YIELD 1 != '1';
+--------+
| (1!=1) |
+--------+
| true   |
+--------+
  • IS [NOT] NULL
nebula> RETURN null IS NULL AS value1, null == null AS value2, null != null AS value3
+--------+----------+----------+
| value1 | value2   | value3   |
+--------+----------+----------+
| true   | __NULL__ | __NULL__ |
+--------+----------+----------+

nebula> RETURN length(NULL), size(NULL), count(NULL), NULL IS NULL, NULL IS NOT NULL, sin(NULL), NULL + NULL, [1, NULL] IS NULL
+--------------+------------+-------------+--------------+------------------+-----------+-------------+------------------+
| length(NULL) | size(NULL) | COUNT(NULL) | NULL IS NULL | NULL IS NOT NULL | sin(NULL) | (NULL+NULL) | [1,NULL] IS NULL |
+--------------+------------+-------------+--------------+------------------+-----------+-------------+------------------+
| BAD_TYPE     | __NULL__   | 0           | true         | false            | BAD_TYPE  | __NULL__    | false            |
+--------------+------------+-------------+--------------+------------------+-----------+-------------+------------------+

nebula> WITH {name: null} AS map RETURN map.name IS NOT NULL
+----------------------+
| map.name IS NOT NULL |
+----------------------+
| false                |
+----------------------+

nebula> WITH {name: 'Mats', name2: 'Pontus'} AS map1, \
       {name: null} AS map2, {notName: 0, notName2: null } AS map3 \
       RETURN map1.name IS NULL, map2.name IS NOT NULL, map3.name IS NULL
+-------------------+-----------------------+-------------------+
| map1.name IS NULL | map2.name IS NOT NULL | map3.name IS NULL |
+-------------------+-----------------------+-------------------+
| false             | false                 | true              |
+-------------------+-----------------------+-------------------+

nebula> MATCH (n:player) RETURN n.age IS NULL, n.name IS NOT NULL, n.empty IS NULL
+---------------+--------------------+-----------------+
| n.age IS NULL | n.name IS NOT NULL | n.empty IS NULL |
+---------------+--------------------+-----------------+
| false         | true               | true            |
+---------------+--------------------+-----------------+
| false         | true               | true            |
+---------------+--------------------+-----------------+
| false         | true               | true            |
+---------------+--------------------+-----------------+
...

Last update: April 22, 2021