跳转至

字符串Graph

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

字符串类型Graph

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

  • 定长字符串
    nebula> CREATE TAG t1 (p1 fixed_string(10)); 
    
  • 变长字符串
    nebula> CREATE TAG t2 (p2 string); 
    

转义字符Graph

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

  • "\n\t\r\b\f"
  • "\110ello world"

OpenCypher兼容性Graph

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

# File: Literals.feature
Feature: Literals

Background:
    Given any graph
 Scenario: Return a single-quoted string
    When executing query:
      """
      RETURN '' AS literal
      """
    Then the result should be, in any order:
      | literal |
      | ''      |    # Note: it should return single-quotes as openCypher required.
    And no side effects

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

nebula > YIELD '' AS quote1, "" AS quote2, "'" AS quote3, '"' AS quote4
+--------+--------+--------+--------+
| quote1 | quote2 | quote3 | quote4 |
+--------+--------+--------+--------+
| ""     | ""     | "'"    | """    |
+--------+--------+--------+--------+

最后更新: 2021年8月19日
Back to top