Skip to main content
Version: 3.10.0

CREATE EDGE

CREATE EDGE creates an edge type with the given name in a graph space.

OpenCypher compatibility​

Edge types in nGQL are similar to relationship types in openCypher. But they are also quite different. For example, the ways to create them are different.

  • In openCypher, relationship types are created together with vertices in CREATE statements.
  • In nGQL, edge types are created separately using CREATE EDGE statements. Edge types in nGQL are more like tables in MySQL.

Prerequisites​

Running the CREATE EDGE statement requires some privileges for the graph space. Otherwise, NebulaGraph throws an error.

Syntax​

To create an edge type in a specific graph space, you must specify the current working space with the USE statement.

CREATE EDGE [IF NOT EXISTS] <edge_type_name>
(
<prop_name> <data_type> [NULL | NOT NULL] [DEFAULT <default_value>] [COMMENT '<comment>']
[{, <prop_name> <data_type> [NULL | NOT NULL] [DEFAULT <default_value>] [COMMENT '<comment>']} ...]
)
[TTL_DURATION = <ttl_duration>]
[TTL_COL = <prop_name>]
[COMMENT = '<comment>'];
ParameterDescription
IF NOT EXISTSDetects if the edge type that you want to create exists. If it does not exist, a new one will be created. The edge type existence detection here only compares the edge type names (excluding properties).
<edge_type_name>1. The edge type name must be unique in a graph space.
2. Once the edge type name is set, it can not be altered.
3. By default, the name only supports 1-4 byte UTF-8 encoded characters, including English letters (case sensitive), numbers, Chinese characters, etc. However, it cannot include special characters other than the underscore (_), and cannot start with a number.
4. To use special characters, reserved keywords, or start with a number, quote the entire name with backticks (`) and do not include periods (.) within the pair of backticks (`). For more information, see Keywords and reserved words.
Note:
1. If you name an edge type in Chinese and encounter a SyntaxError, you need to quote the Chinese characters with backticks (`).
2. To include a backtick (`) in an edge type name, use a backslash to escape the backtick, such as \`; to include a backslash, the backslash itself also needs to be escaped, such as \\ .
<prop_name>The name of the property. It must be unique for each edge type. The rules for permitted property names are the same as those for edge type names.
<data_type>The data type of the property. The following data types are supported: Numeric, Boolean, String, Date and time, and Geography.
`NULLNOT NULL`
DEFAULTSpecifies a default value for a property. The default value can be a literal value or an expression supported by NebulaGraph. If no value is specified, the default value is used when inserting a new edge.
COMMENTThe remarks of a certain property or the edge type itself. The maximum length is 256 bytes. By default, there will be no comments on an edge type.
TTL_DURATIONSpecifies the life cycle for the property. The property that exceeds the specified TTL expires. The expiration threshold is the TTL_COL value plus the TTL_DURATION. The default value of TTL_DURATION is 0. It means the data never expires.
TTL_COLSpecifies the property to set a timeout on. The data type of the property must be int or timestamp. An edge type can only specify one field as TTL_COL. For more information on TTL, see TTL options.

Examples​

nebula> CREATE EDGE IF NOT EXISTS follow(degree int);

# The following example creates an edge type with no properties.
nebula> CREATE EDGE IF NOT EXISTS no_property();

# The following example creates an edge type with a default value.
nebula> CREATE EDGE IF NOT EXISTS follow_with_default(degree int DEFAULT 20);

# In the following example, the TTL of the p2 field is set to be 100 seconds.
nebula> CREATE EDGE IF NOT EXISTS e1(p1 string, p2 int, p3 timestamp) \
TTL_DURATION = 100, TTL_COL = "p2";