UltipaDocs
Try Playground
  • Introduction
    • Overview
    • Node and Edge Patterns
    • Path Patterns
    • Quantified Paths
    • Shortest Paths
    • Graph Patterns
    • Overview
    • Typed Graph
    • Open Graph
    • Graph Sharding and Storage
    • Constraints
    • Unique Identifiers
    • INSERT
    • INSERT OVERWRITE
    • UPSERT
    • SET
    • REMOVE
    • DELETE
    • Query Composition
    • Result Table and Visualization
    • MATCH
    • OPTIONAL MATCH
    • FILTER
    • LET
    • FOR
    • ORDER BY
    • LIMIT
    • SKIP
    • CALL
    • RETURN
    • Composite Query
    • NEXT
    • All Functions
    • Scalar Functions
    • Path Functions
    • Aggregate Functions
    • Mathematical Functions
    • Trigonometric Functions
    • String Functions
    • List Functions
    • Datetime Functions
    • Spatial Functions
    • Table Functions
  • Operators
  • Predicates
  • Expressions
    • Index
    • Full-text Index
    • Vector Index
    • Managing HDC Graphs
    • HDC Graph Queries
  • Transaction
  • Trigger
    • Process
    • Job
    • Execution Plan
    • Variables
    • Values and Types
    • Comments
    • Reserved Words
    • Syntactic Notation
  • Access Control
  • GQL Conformance
  1. Docs
  2. /
  3. ISO GQL
  4. /
  5. Data Modification

INSERT OVERWRITE

Overview

The INSERT OVERWRITE statement allows you to overwrite existing nodes and edges in the graph. If no existing data is found, it will insert new nodes or edges instead.

In typed graphs, each node or edge belongs to exactly one schema, and the assigned schema cannot be changed after insertion. Attempting to overwrite a node or edge with a different schema will result in an error. When a node or edge is overwritten, the properties specified in the new definition will be updated, while any properties not included will be set to null.

On the other hand, when a node or edge is overwritten in open graphs, both its label and property are updated to the new definition.

Overwriting Nodes

An existing node will be overwritten if _id is included in the property specification and its value can be found in the graph. For example:

GQL
INSERT OVERWRITE (:User {_id: "U2", name: "Jumpy88"})

If a node with _id equal to U2 already exists in the graph, its schema/label and properties will be overwritten with the new values. If no such node exists, a new node will be inserted.

GQL
INSERT OVERWRITE (:User {name: "Jumpy88"})

Since the property specification does not include _id, a new node will be inserted into the graph.

Overwriting Edges

An existing edge is overwritten if the EDGE KEY property is included in the property specification and its value can be found in the graph. In addition, the specified source and destination nodes must remain the same.

For example, the EDGE KEY constraint applies to the property eID:

GQL
ALTER EDGE * ADD CONSTRAINT EDGE KEY ON eID STRING

Learn more about the EDGE KEY constraint →

GQL
MATCH (n1:User {name: "mochaeach"}), (n2:User {name: "Brainy"})
INSERT OVERWRITE (n1)-[e:Follows {eID: "e6561"}]->(n2)

If an edge with eID equal to e6561 already exists in the graph and its source and destination nodes are mochaeach and Brainy respectively, its schema/label and properties will be overwritten with the new values. If no such edge exists, a new edge will be inserted.