比较符

Nebula Graph支持的比较符如下。

符号说明
=赋值
+加法
-减法
*乘法
/除法
==相等
!=, <>不等于
<小于
<=小于等于
%取模
-负数符号
IS NULL为NULL
IS NOT NULL不为NULL

比较操作的结果是true或者false

说明:比较不同类型的值通常没有定义,结果可能是NULL或其它。

OpenCypher兼容性

Nebula Graph中,NULL的比较操作和openCypher不同,行为也可能会改变。在openCypher中,IS [NOT] NULL通常与OPTIONAL MATCH一起使用,但是nGQL不支持OPTIONAL MATCH

示例

==

字符串比较时,会区分大小写。不同类型的值不相等。

说明:nGQL中的相等符号是==,openCypher中的相等符号是=

  1. nebula> RETURN 'A' == 'a', toUpper('A') == toUpper('a'), toLower('A') == toLower('a');
  2. +------------+------------------------------+------------------------------+
  3. | ("A"=="a") | (toUpper("A")==toUpper("a")) | (toLower("A")==toLower("a")) |
  4. +------------+------------------------------+------------------------------+
  5. | false | true | true |
  6. +------------+------------------------------+------------------------------+
  7. nebula> RETURN '2' == 2, toInteger('2') == 2;
  8. +----------+---------------------+
  9. | ("2"==2) | (toInteger("2")==2) |
  10. +----------+---------------------+
  11. | false | true |
  12. +----------+---------------------+

>

  1. nebula> RETURN 3 > 2;
  2. +-------+
  3. | (3>2) |
  4. +-------+
  5. | true |
  6. +-------+
  7. nebula> WITH 4 AS one, 3 AS two \
  8. RETURN one > two AS result;
  9. +--------+
  10. | result |
  11. +--------+
  12. | true |
  13. +--------+

>=

  1. nebula> RETURN 2 >= "2", 2 >= 2;
  2. +----------+--------+
  3. | (2>="2") | (2>=2) |
  4. +----------+--------+
  5. | __NULL__ | true |
  6. +----------+--------+

<

  1. nebula> YIELD 2.0 < 1.9;
  2. +---------+
  3. | (2<1.9) |
  4. +---------+
  5. | false |
  6. +---------+

<=

  1. nebula> YIELD 0.11 <= 0.11;
  2. +--------------+
  3. | (0.11<=0.11) |
  4. +--------------+
  5. | true |
  6. +--------------+

!=

  1. nebula> YIELD 1 != '1';
  2. +--------+
  3. | (1!=1) |
  4. +--------+
  5. | true |
  6. +--------+

IS [NOT] NULL

  1. nebula> RETURN null IS NULL AS value1, null == null AS value2, null != null AS value3;
  2. +--------+----------+----------+
  3. | value1 | value2 | value3 |
  4. +--------+----------+----------+
  5. | true | __NULL__ | __NULL__ |
  6. +--------+----------+----------+
  7. nebula> RETURN length(NULL), size(NULL), count(NULL), NULL IS NULL, NULL IS NOT NULL, sin(NULL), NULL + NULL, [1, NULL] IS NULL;
  8. +--------------+------------+-------------+--------------+------------------+-----------+-------------+------------------+
  9. | length(NULL) | size(NULL) | COUNT(NULL) | NULL IS NULL | NULL IS NOT NULL | sin(NULL) | (NULL+NULL) | [1,NULL] IS NULL |
  10. +--------------+------------+-------------+--------------+------------------+-----------+-------------+------------------+
  11. | BAD_TYPE | __NULL__ | 0 | true | false | BAD_TYPE | __NULL__ | false |
  12. +--------------+------------+-------------+--------------+------------------+-----------+-------------+------------------+
  13. nebula> WITH {name: null} AS map \
  14. RETURN map.name IS NOT NULL;
  15. +----------------------+
  16. | map.name IS NOT NULL |
  17. +----------------------+
  18. | false |
  19. +----------------------+
  20. nebula> WITH {name: 'Mats', name2: 'Pontus'} AS map1, \
  21. {name: null} AS map2, {notName: 0, notName2: null } AS map3 \
  22. RETURN map1.name IS NULL, map2.name IS NOT NULL, map3.name IS NULL;
  23. +-------------------+-----------------------+-------------------+
  24. | map1.name IS NULL | map2.name IS NOT NULL | map3.name IS NULL |
  25. +-------------------+-----------------------+-------------------+
  26. | false | false | true |
  27. +-------------------+-----------------------+-------------------+
  28. nebula> MATCH (n:player) \
  29. RETURN n.age IS NULL, n.name IS NOT NULL, n.empty IS NULL;
  30. +---------------+--------------------+-----------------+
  31. | n.age IS NULL | n.name IS NOT NULL | n.empty IS NULL |
  32. +---------------+--------------------+-----------------+
  33. | false | true | true |
  34. +---------------+--------------------+-----------------+
  35. | false | true | true |
  36. +---------------+--------------------+-----------------+
  37. | false | true | true |
  38. +---------------+--------------------+-----------------+
  39. ...