Fixed-length strings and variable-length strings are supported.
Declaration and literal representation¶
The string type is declared with the keywords of:
STRING: Variable-length strings.
FIXED_STRING(<length>): Fixed-length strings.
<length>is the length of the string, such as
A string type is used to store a sequence of characters (text). The literal constant is a sequence of characters of any length surrounded by double or single quotes. For example,
"Hello, Cooper" or
String reading and writing¶
Nebula Graph supports using string types in the following ways:
- Define the data type of VID as a fixed-length string.
- Set the variable-length string as the Schema name, including the names of the graph space, tag, edge type, and property.
- Define the data type of the property as a fixed-length or variable-length string.
- Define the data type of the property as a fixed-length string
nebula> CREATE TAG IF NOT EXISTS t1 (p1 FIXED_STRING(10));
- Define the data type of the property as a variable-length string
nebula> CREATE TAG IF NOT EXISTS t2 (p2 STRING);
When the fixed-length string you try to write exceeds the length limit:
- If the fixed-length string is a property, the writing will succeed, and NebulaGraph will truncate the string and only store the part that meets the length limit.
- If the fixed-length string is a VID, the writing will fail and NebulaGraph will return an error.
Line breaks are not allowed in a string. Escape characters are supported within strings, for example:
There are some tiny differences between openCypher and Cypher, as well as nGQL. The following is what openCypher requires. Single quotes cannot be converted to double quotes.
# 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
While Cypher accepts both single quotes and double quotes as the return results. nGQL follows the Cypher way.
nebula > YIELD '' AS quote1, "" AS quote2, "'" AS quote3, '"' AS quote4 +--------+--------+--------+--------+ | quote1 | quote2 | quote3 | quote4 | +--------+--------+--------+--------+ | "" | "" | "'" | """ | +--------+--------+--------+--------+