Skip to content
Developer Edition runs on one host and does not require a product license file. Need multi-host deployment or performance testing at scale? Explore Enterprise Edition

ALTER GRAPH TYPE statement

The ALTER GRAPH TYPE statement modifies a graph type in the schema of the current session or a specified schema, including the node types and edge types defined by the graph type.

The following tables list the actions that can be performed on node types and edge types using the ALTER GRAPH TYPE statement.

Node types

Action Description
Add node types Add new node types to the graph type.
Drop node types Remove existing node types from the graph type.
Rename node types Change the name of existing node types.
Alter labels Add or drop labels for node types.
- Add Labels Add new labels to node types.
- Drop Labels Remove labels from node types.
Alter properties Add, drop, rename, or modify properties for node types.
- Add Properties Add new properties to node types.
- Drop Properties Remove properties from node types.
- Rename Properties Change the name of existing properties.
- Modify Properties Change the value type, nullability, or default value of existing properties of node types.

Edge types

Action Description
Add edge types Add new edge types to the graph type.
Drop edge types Remove existing edge types from the graph type.
Rename edge types Change the name of existing edge types.
Alter Labels Add or drop labels for edge types.
- Add Labels Add new labels to edge types.
- Drop Labels Remove labels from edge types.
Alter Properties Add, drop, rename, or modify properties for edge types.
- Add Properties Add new properties to edge types.
- Drop Properties Remove properties from edge types.
- Rename Properties Change the name of existing properties.
- Modify Properties Change the value type, nullability, or default value of existing properties of edge types.

Note

  • After a graph type is modified, the nodes and edges in all graphs of that graph type are also modified accordingly. When a node type or edge type is dropped, all nodes or edges of the deleted type are not immediately physically deleted from the Storage service (disk space remains occupied). Instead, they are permanently deleted during the subsequent RocksDB Compaction operations.
  • If a property of a node type or edge type is used to create an index, the index is automatically dropped when the property, node type, or edge type is dropped.

Note

An operation involving a non-default schema or an object in it requires access to the schema, either implicitly or through an explicit USAGE grant, as well as the privilege required for the operation. The schema access check and the privilege check for the requested operation are independent; satisfying one does not satisfy the other. Schema access control does not apply to temporary graphs or built-in procedures and functions. For more information, see Schema access control.

Prerequisites

  • To alter a graph type, you must either be the owner of the graph type, be granted to perform the action ALTER on the graph type, or be granted to perform the action ALTER ANY GRAPH TYPE on the corresponding schema. For more information, see Roles and privileges.

Limitations

  • Primary keys
    • The primary key of an existing node type cannot be redefined. Properties cannot be added to, removed from, or replaced in the primary key.
    • MODIFY PROPERTIES cannot be used to change the value type, nullability, or default value of a primary key property.
    • Primary keys must be specified when adding new node types.
  • Multi-edge keys
    • The multi-edge key of an existing edge type cannot be redefined. Properties cannot be added to, removed from, or replaced in the multi-edge key.
    • MODIFY PROPERTIES cannot be used to change the value type, nullability, or default value of a multi-edge key property.
    • Multi-edge keys may be specified when adding new edge types.
  • Node types and edge types
    • Each node type or edge type can be altered only once in the same ALTER GRAPH TYPE statement. Example: If a node type is renamed from A to B, you cannot drop node type B or add a new node type named A in the same statement.
  • Labels
    • Each label of a node type or edge type can be altered only once in the same ALTER GRAPH TYPE statement. Example: You cannot add label A and drop label A in the same statement.
  • Properties
    • Each property of a node type or edge type can be altered only once in the same ALTER GRAPH TYPE statement. Example: If a property is renamed from A to B, you cannot drop property B or add a new property named A in the same statement.
    • When modifying properties:
      • A property referenced by a normal, full-text, or vector index in any graph created from the graph type cannot be modified by using MODIFY PROPERTIES. Before modifying the property, drop every index that references it.
      • Changing a property from nullable to not nullable is not allowed.
      • Changes to the value type, nullability, and default value of a property must be made together.
      • Modifications are allowed only when implicit type conversion is possible. For example, changing the value type from INT32 to INT64 is supported. For more information, see Data type conversions.

Syntax

alter_graph_type_statement
ALTER PROPERTY GRAPH TYPE schema_reference / graph_type_name { alter_graph_type_specification , }
alter_graph_type_specification
ADD NODE VERTEX TYPE IF NOT EXISTS node_type_name node_type_filler ADD EDGE RELATIONSHIP TYPE IF NOT EXISTS edge_type_name ( source_node_type_name ) -[ edge_type_filler ]-> ( destination_node_type_name ) ( destination_node_type_name ) <-[ edge_type_filler ]- ( source_node_type_name ) ( source_node_type_name ) ~[ edge_type_filler ]~ ( destination_node_type_name ) DROP NODE VERTEX EDGE RELATIONSHIP TYPE IF EXISTS element_type_name RENAME NODE VERTEX EDGE RELATIONSHIP TYPE old_element_type_name TO new_element_type_name ALTER NODE VERTEX EDGE RELATIONSHIP TYPE element_type_name alter_element_type_op
node_type_filler
LABEL label_name LABELS IS : label_name & { property_name :: TYPED property_value_type NULL NOT NULL DEFAULT value_expression PRIMARY KEY , , primary_key_list }
primary_key_list
PRIMARY KEY ( property_name , )
edge_type_filler
LABEL label_name LABELS IS : label_name & { property_name :: TYPED property_value_type NULL NOT NULL DEFAULT value_expression MULTIEDGE KEY , , multiedge_key_list } { MULTIEDGE KEY ( ) }
multiedge_key_list
MULTIEDGE KEY ( property_name , )
alter_element_type_op
ADD LABELS IF NOT EXISTS label_name & DROP LABELS IF EXISTS label_name & ADD PROPERTIES IF NOT EXISTS { property_name :: TYPED property_value_type NULL NOT NULL DEFAULT value_expression , } DROP PROPERTIES IF EXISTS { property_name , } RENAME PROPERTIES { old_property_name TO new_property_name , } MODIFY PROPERTIES { property_name :: TYPED property_value_type NULL NOT NULL DEFAULT value_expression , }

alter_graph_type_statement ::= 
    'ALTER'  'PROPERTY'? 'GRAPH TYPE' (schema_reference '/')? graph_type_name '{' alter_graph_type_specification ( ',' alter_graph_type_specification )* '}'

alter_graph_type_specification ::= 
    ADD ('NODE' | 'VERTEX') 'TYPE'? ('IF NOT EXISTS')? node_type_name ( node_type_filler )
    | ADD ('EDGE' | 'RELATIONSHIP') 'TYPE'? ('IF NOT EXISTS')? edge_type_name ('(' source_node_type_name ')' '-[' edge_type_filler ']->' '(' destination_node_type_name ')'
    | '(' destination_node_type_name ')' '<-[' edge_type_filler ']-' '(' source_node_type_name ')'
    | '(' source_node_type_name ')' '~[' edge_type_filler ']~' '(' destination_node_type_name ')')
    | DROP ( ('NODE' | 'VERTEX') | ('EDGE' | 'RELATIONSHIP') ) 'TYPE'? ('IF EXISTS')? element_type_name
    | RENAME ( ('NODE' | 'VERTEX') | ('EDGE' | 'RELATIONSHIP') ) 'TYPE'? old_element_type_name 'TO' new_element_type_name
    | ALTER ( ('NODE' | 'VERTEX') | ('EDGE' | 'RELATIONSHIP') ) 'TYPE'? element_type_name alter_element_type_op+

node_type_filler ::=
    ('LABEL' label_name | ( 'LABELS' | ( 'IS' | ':' ) ) label_name ('&' label_name)*)? 
   ( ('{'   
       (property_name ('::' | 'TYPED')? property_value_type ('NULL' | 'NOT NULL' | 'DEFAULT' value_expression | 'PRIMARY KEY' )*) 
       (',' (property_name ('::' | 'TYPED')? property_value_type ('NULL' | 'NOT NULL' | 'DEFAULT' value_expression| 'PRIMARY KEY' )*))* 
       (',' primary_key_list)?            
    '}')
   ) 

primary_key_list ::=
    'PRIMARY KEY' '(' property_name (',' property_name)* ')'     

edge_type_filler ::=

      ( 'LABEL' label_name | ( 'LABELS' | ( 'IS' | ':' ) ) label_name ('&' label_name)*)? 
      ('{'  
          (property_name ('::' | 'TYPED')? property_value_type ('NULL' | 'NOT NULL' | 'DEFAULT' value_expression | 'MULTIEDGE KEY' )*) 
          (',' (property_name ('::' | 'TYPED')? property_value_type ('NULL' | 'NOT NULL' | 'DEFAULT' value_expression | 'MULTIEDGE KEY')*))* 
          (',' multiedge_key_list)? 
        '}' 
      | '{' ('MULTIEDGE KEY ( )')? '}')

multiedge_key_list ::=
    'MULTIEDGE KEY' '(' (property_name ( ',' property_name)* )? ')' 

alter_element_type_op ::=
    'ADD' 'LABELS' ('IF NOT EXISTS')? label_name ('&' label_name)*
    | 'DROP' 'LABELS' ('IF EXISTS')? label_name ('&' label_name)*
    | 'ADD' 'PROPERTIES' ('IF NOT EXISTS')? '{'  
          (property_name ('::' | 'TYPED')? property_value_type ('NULL' | 'NOT NULL' | 'DEFAULT' value_expression )*) 
          (',' (property_name ('::' | 'TYPED')? property_value_type ('NULL' | 'NOT NULL' | 'DEFAULT' value_expression)*))* '}'
    | 'DROP' 'PROPERTIES' ('IF EXISTS')? '{' property_name (',' property_name)* '}'
    | 'RENAME' 'PROPERTIES' '{' (old_property_name 'TO' new_property_name) (',' (old_property_name 'TO' new_property_name))* '}'
    | 'MODIFY' 'PROPERTIES' '{'  
          (property_name ('::' | 'TYPED')? property_value_type ('NULL' | 'NOT NULL' | 'DEFAULT' value_expression )*) 
          (',' (property_name ('::' | 'TYPED')? property_value_type ('NULL' | 'NOT NULL' | 'DEFAULT' value_expression)*))* '}'

Parameters

IF NOT EXISTS

This clause checks if an element (which may be node type, edge type, label, or property) with the same name already exists. If it does already exist, the element is not added and no exception is thrown.

If you do not specify this clause, an exception is thrown if an element with the same name already exists.

schema_reference

The reference to the path of the schema. It specifies the schema path of the graph type to be altered here.

Both absolute and relative schema paths can be used in the statement. To alter a graph type that resides outside the schema in the current session, the schema path must be specified. For information about setting and viewing the schema, see SESSION SET and SHOW CURRENT_SCHEMA.

graph_type_name

The name of the graph type to be altered.

node_type_name

The name of the node type. The name must be unique among all node types and edge types of the graph type.

label_name

The name of the label of the node type or edge type. The name of a label must be unique within a node type or edge type.

property_name

The name of the property of the node type or edge type. The name of a property must be unique within a node type or edge type. However, within a graph type, if multiple properties share a name, these properties must be of the same value type.

property_value_type

The value type of a property of a node type or edge type in the graph type. For more information, see CREATE GRAPH TYPE.

primary_key_list

The list of properties of a node type that functions as the primary key. For more information, see CREATE GRAPH TYPE.

multiedge_key_list

The list of properties of an edge type based on which the multi-edge key is created. For more information, see CREATE GRAPH TYPE.

edge_type_name

The name of the edge type. The name must be unique among all node types and edge types of the graph type.

source_node_type_name

The name of the source node type of the edge type. The source node type must be one of the node types defined in the graph type.

destination_node_type_name

The name of the destination node type of the edge type. The destination node type must be one of the node types defined in the graph type.

IF EXISTS

This clause checks if the element (which may be node type, edge type, label, or property) to be deleted exists. If it does not exist, the element is not deleted and no exception is thrown.

If you do not specify this clause, an exception is thrown if the element to be deleted does not exist.

element_type_name

The name of the node type or edge type.

old_element_type_name

The current name of the node type or edge type.

new_element_type_name

The new name of the node type or edge type.

old_property_name

The current name of the property.

new_property_name

The new name of the property.

Examples

The following examples are based on the example dataset.

Add a node type and an edge type to a graph type in the current schema

'''
ALTER GRAPH TYPE movie_type { 
    ADD NODE TYPE Company (LABEL Company {id INT PRIMARY KEY, name STRING}), 
    ADD EDGE TYPE Serve (Director)-[LABEL Serve{start_year INT, end_year INT}]->(Company) 
}
'''

The preceding example adds a node type Company and an edge type Serve to the graph type movie_type in the current schema.

Add a node type and an edge type to a graph type in a specified schema

'''
// Create a schema
CREATE SCHEMA IF NOT EXISTS /my_schema
''' 

'''
// Set the schema for the current session
SESSION SET SCHEMA /my_schema
'''

'''
// Add a node type and an edge type
ALTER GRAPH TYPE /default_schema/movie_type { 
    ADD NODE TYPE Company (LABEL Company {id INT PRIMARY KEY, name STRING}), 
    ADD EDGE TYPE Serve (Director)-[LABEL Serve{start_year INT, end_year INT}]->(Company) 
}
'''

The preceding examples add a node type Company and an edge type Serve to the graph type movie_type in the specified schema /default_schema when the schema for the current session is set to /my_schema.

Drop a node type and an edge type

'''
ALTER GRAPH TYPE movie_type { 
    DROP NODE TYPE Company, 
    DROP EDGE TYPE Serve 
}
'''

The preceding example drops the node type Company and the edge type Serve.

Rename a node type and an edge type

'''
ALTER GRAPH TYPE movie_type { 
    RENAME NODE TYPE Actor TO Actor_renamed, 
    RENAME EDGE TYPE Act TO Act_renamed 
}
'''

The preceding example renames the node type Actor to Actor_renamed and the edge type Act to Act_renamed.

Add labels to a node type and an edge type

'''
ALTER GRAPH TYPE movie_type { 
    ALTER NODE TYPE `User` ADD LABELS Male&Above30, 
    ALTER EDGE TYPE Watch ADD LABELS InCinema&AtHome 
}
'''

The preceding example adds the labels Male and Above30 to the node type User and the labels InCinema and AtHome to the edge type Watch.

Drop labels from a node type and an edge type

'''
ALTER GRAPH TYPE movie_type { 
    ALTER NODE TYPE `User` DROP LABELS Male&Above30, 
    ALTER EDGE TYPE Watch DROP LABELS InCinema&AtHome 
}
'''

The preceding example drops the labels Male and Above30 from the node type User and the labels InCinema and AtHome from the edge type Watch.

Add properties to a node type and an edge type

'''
ALTER GRAPH TYPE movie_type { 
    ALTER NODE TYPE `User` ADD PROPERTIES {email STRING, age INT64}, 
    ALTER EDGE TYPE Watch ADD PROPERTIES {`count` INT64, platform STRING} 
}
'''

The preceding example adds the properties email and age to the node type User and the properties count and platform to the edge type Watch.

Drop properties from a node type and an edge type

'''
ALTER GRAPH TYPE movie_type { 
    ALTER NODE TYPE `User` DROP PROPERTIES {email, age}, 
    ALTER EDGE TYPE Watch DROP PROPERTIES {`count`, platform} 
}
'''

The preceding example drops the properties email and age from the node type User and the properties count and platform from the edge type Watch.

Rename properties of a node type and an edge type

'''
ALTER GRAPH TYPE movie_type { 
    ALTER NODE TYPE Director RENAME PROPERTIES {birthDate TO birth, name TO lastName }, 
    ALTER EDGE TYPE Watch RENAME PROPERTIES {`rate` TO rating} 
}
'''

The preceding example renames the properties birthDate and name of the node type Director to birth and lastName, respectively, and renames the property rate of the edge type Watch to rating.

Modify properties of a node type and an edge type

'''
ALTER GRAPH TYPE movie_type { 
    ALTER NODE TYPE Director MODIFY PROPERTIES {name STRING DEFAULT "Alex", birthDate DATE DEFAULT date("2016-09-20") },
    ALTER EDGE TYPE Watch MODIFY PROPERTIES {rate FLOAT DEFAULT 4.5} 
}
'''

The preceding example modifies the default values of the properties name and birthDate of the node type Director to Alex and 2016-09-20", respectively, and modifies the default value of the property rate of the edge type Watch to 4.5.