CREATE EDGE creates an edge type with the given name in a graph space. You must have the
CREATE privilege for the graph space. To create an edge type in a specific graph space, you must use the graph space first.
Edge types in nGQL are similar to labels/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 relationships by
- In nGQL, edge types are created separately by
CREATE EDGEstatements. Edge types in nGQL are more like tables in MySQL.
CREATE EDGE [IF NOT EXISTS] <edge_type_name> ([<create_definition>, ...]) [edge_type_options] <create_definition> ::= <prop_name> <data_type> <edge_type_options> ::= <option> [, <option> ...] <option> ::= TTL_DURATION [=] <ttl_duration> | TTL_COL [=] <prop_name> | DEFAULT <default_value>
Edge type name¶
IF NOT EXISTS: Creating an existent edge type causes an error. You can use the
IF NOT EXISTSoption to conditionally create the edge type and avoid the error.
NOTE: The edge type existence detection here compares only the edge type names (excluding properties). -
edge_type_name: The edge type name must be unique in a graph space. Once the edge type name is set, it can not be altered. The rules for permitted edge type names are the same as those for graph space names. For prohibited names, see Keywords and reserved words.
Property names and data types¶
prop_nameis the name of the property. It must be unique for each edge type.
data_typeshows the data type of each property. For a full description of the property data types, see Data types.
NULL | NOT NULL
Specifies if the property supports
NULL | NOT NULL. The default value is
Specifies a default value for a property. The default value can be a literal value or an expression supported by Nebula Graph. If no value is specified, the default value is used when inserting a new vertex.
Specifies the life cycle for the data. Data that exceeds the specified TTL expires. The expiration threshold is the
TTL_COLvalue plus the
TTL_DURATION. The default value of
0. It means the data never expires.
The data type of
prop_namemust be either
- single TTL definition
TTL_COLfield can be specified in an edge type.
For more information about TTL, see TTL options.
nebula> CREATE EDGE follow(degree int); // Create an edge type with no properties. nebula> CREATE EDGE no_property(); // Create an edge type with a default value. nebula> CREATE EDGE follow_with_default(degree int DEFAULT 20);
// Time interval is 100s, starting from the p2 field // Data expires after TTL_DURATION nebula> CREATE EDGE e1(p1 string, p2 int, \ p3 timestamp) \ TTL_DURATION = 100, TTL_COL = "p2";
Implementation of the operation¶
Trying to insert edges of a newly created edge type may fail, because the creation of the edge type is implemented asynchronously.
Nebula Graph implements the creation in the next heartbeat cycle. To make sure the creation is successful, take the following approaches:
- Find the new edge type in the result of
SHOW EDGES. If you can't, wait a few seconds and try again.
- Wait for two heartbeat cycles, i.e., 20 seconds.
To change the heartbeat interval, modify the
heartbeat_interval_secs parameter in the configuration files for all services.