字符串

Nebula Graph使用关键字string(变长)或fixed_string(<length>)(定长)声明字符串类型数据,格式为双引号或单引号包裹的任意长度的字符串,例如"Shaquille O'Neal"'This is a single-quoted literal string'

字符串类型

Nebula Graph支持定长字符串和变长字符串。示例如下:

  • 定长字符串

    1. nebula> CREATE TAG t1 (p1 fixed_string(10));
  • 变长字符串

    1. nebula> CREATE TAG t2 (p2 string);

转义字符

字符串中不支持直接换行,可以使用转义字符实现,例如:

  • "\n\t\r\b\f"

  • "\110ello world"

OpenCypher兼容性

openCypher、Cypher和nGQL之间有一些细微区别,例如下面openCypher的示例,不能将单引号替换为双引号。

  1. # File: Literals.feature
  2. Feature: Literals
  3. Background:
  4. Given any graph
  5. Scenario: Return a single-quoted string
  6. When executing query:
  7. """
  8. RETURN '' AS literal
  9. """
  10. Then the result should be, in any order:
  11. | literal |
  12. | '' | # Note: it should return single-quotes as openCypher required.
  13. And no side effects

Cypher的返回结果同时支持单引号和双引号,nGQL遵循Cypher的方式。

  1. nebula > YIELD '' AS quote1, "" AS quote2, "'" AS quote3, '"' AS quote4
  2. +--------+--------+--------+--------+
  3. | quote1 | quote2 | quote3 | quote4 |
  4. +--------+--------+--------+--------+
  5. | "" | "" | "'" | """ |
  6. +--------+--------+--------+--------+