Comparison operators¶
NebulaGraph supports the following comparison operators.
Name | Description |
---|---|
= |
Assigns a value |
+ |
Addition operator |
- |
Minus operator |
* |
Multiplication operator |
/ |
Division operator |
== |
Equal operator |
!= , <> |
Not equal operator |
> |
Greater than operator |
>= |
Greater than or equal operator |
< |
Less than operator |
<= |
Less than or equal operator |
% |
Modulo operator |
- |
Changes the sign of the argument |
IS NULL |
NULL check |
IS NOT NULL |
Not NULL check |
IS EMPTY |
EMPTY check |
IS NOT EMPTY |
Not EMPTY check |
The result of the comparison operation is true
or false
.
Note
- Comparability between values of different types is often undefined. The result could be
NULL
or others.
EMPTY
is currently used only for checking, and does not support functions or operations such asGROUP BY
,count()
,sum()
,max()
,hash()
,collect()
,+
or*
.
OpenCypher compatibility¶
- The comparison operation of
NULL
is different from openCypher. The behavior may also change.IS [NOT] NULL
is often used withOPTIONAL MATCH
in openCypher. ButOPTIONAL MATCH
is not supported in nGQL.
- openCypher does not have
EMPTY
. ThusEMPTY
is not supported in MATCH statements.
Examples¶
==
¶
String comparisons are case-sensitive. Values of different types are not equal.
Note
The equal operator is ==
in nGQL, while in openCypher it is =
.
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 |
+----------+---------------------+
>
¶
nebula> RETURN 3 > 2;
+-------+
| (3>2) |
+-------+
| true |
+-------+
nebula> WITH 4 AS one, 3 AS two \
RETURN one > two AS result;
+--------+
| result |
+--------+
| true |
+--------+
>=
¶
nebula> RETURN 2 >= "2", 2 >= 2;
+----------+--------+
| (2>="2") | (2>=2) |
+----------+--------+
| __NULL__ | true |
+----------+--------+
<
¶
nebula> YIELD 2.0 < 1.9;
+---------+
| (2<1.9) |
+---------+
| false |
+---------+
<=
¶
nebula> YIELD 0.11 <= 0.11;
+--------------+
| (0.11<=0.11) |
+--------------+
| true |
+--------------+
!=
¶
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 |
+--------------+------------+-------------+--------------+------------------+-----------+-------------+------------------+
| __NULL__ | __NULL__ | 0 | true | false | __NULL__ | __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 |
+---------------+--------------------+-----------------+
...
IS [NOT] EMPTY
¶
nebula> RETURN null IS EMPTY;
+---------------+
| NULL IS EMPTY |
+---------------+
| false |
+---------------+
nebula> RETURN "a" IS NOT EMPTY;
+------------------+
| "a" IS NOT EMPTY |
+------------------+
| true |
+------------------+
nebula> GO FROM "player100" OVER * WHERE $$.player.name IS NOT EMPTY YIELD dst(edge);
+-------------+
| dst(EDGE) |
+-------------+
| "team204" |
| "player101" |
| "player125" |
+-------------+
Last update:
March 13, 2023