UltipaDocs
Try Playground
  • Introduction
  • Terminologies
    • Reserved Words
    • Data Types
    • Alias
    • Operators
    • Expression
    • Filter
    • Prefix
    • Node and Edge Templates
    • Homologous and Heterologous Data
    • Clause Execution Times
    • Graphset
    • Schema
    • Property
    • Insert
    • Overwrite
    • Upsert
    • Update
    • Delete
    • Find Nodes
    • Find Edges
      • AB
      • Autonet
      • Spread
      • Path Template
      • K-Hop
      • K-Hop Template
    • Find Subgraphs
    • GROUP BY
    • ORDER BY
    • SKIP
    • LIMIT
    • WHERE
    • RETURN
    • WITH
    • UNCOLLECT
    • UNION
    • UNION ALL
    • CALL
    • BATCH
      • Schema Checker
      • Equal
      • Not Equal
      • Less Than
      • Greater Than
      • Less Than or Equal
      • Greater Than or Equal
      • Between
      • Between or Equal
      • Beong to
      • Not Belong To
      • CONTAINS | String
      • CONTAINS | Full-Text
      • Regular Match
      • IS NULL
      • IS NOT NULL
      • And
      • Or
      • Not
      • Exclusive OR
      • DISTINCT
      • toString()
      • toInteger()
      • toFloat()
      • toDouble()
      • toDecimal()
      • toSet()
      • castToRaw()
      • now()
      • dateAdd()
      • dateDiff()
      • year()
      • month()
      • day()
      • dayOfWeek()
      • dateFormat()
      • point()
      • distance()
      • pointInPolygon()
      • lower()
      • upper()
      • reverse()
      • startsWith()
      • endsWith()
      • JSON_decode()
      • JSON_merge()
      • trim()
      • ltrim()
      • rtrim()
      • left()
      • right()
      • substring()
      • replace()
      • split()
      • intersection()
      • difference()
      • listUnion()
      • size()
      • head()
      • reduce()
      • listContains()
      • append()
      • pi()
      • pow()
      • sqrt()
      • abs()
      • floor()
      • ceil()
      • round()
      • sin()
      • cos()
      • tan()
      • cot()
      • asin()
      • acos()
      • atan()
      • length()
      • pnodes()
      • pedges()
      • count()
      • sum()
      • max()
      • min()
      • avg()
      • stddev()
      • collect()
      • dedup()
      • CASE
      • table()
      • coalesce()
      • ifnull()
    • Acceleration
    • Index
    • Full-text
    • LTE
    • Real-time Process
    • Backend Task
    • Analytics Node
    • Server Statistics
    • Server Backup
    • Privilege
    • Policy
    • User
  • Trigger
  1. Docs
  2. /
  3. UQL
  4. /
  5. Insert | Update | Delete

Overwrite

Overview

The insert().overwrite().into() clause facilitates either the overwriting of existing nodes or edges within a single schema or the insertion of new nodes or edges.

Syntax

Syntax
// Overwrite or insert nodes
insert().overwrite().into(@<schema>).nodes([
  {<property1>: <value1>, <property2>: <value2>, ...},
  {<property1>: <value1>, <property2>: <value2>, ...}
])

// Overwrite or insert edges
insert().overwrite().into(@<schema>).edges([
  {<property1>: <value1>, <property2>: <value2>, ...},
  {<property1>: <value1>, <property2>: <value2>, ...}
])
  • Specify one schema in the into() method.
  • Include one or multiple nodes or edges in the nodes() or edges() method.
    • Provide key-value pairs of properties for each node or edge enclosed in { }.
    • If there is only one node or edge, the outer [ ] can be omitted.
  • Allow to define an alias for the clause, with the data type being either NODE or EDGE.

When a node or edge is overwritten:

  • A targeted node is specified by its _id and/or _uuid. A targeted edge is specified by its _uuid, _from and _to (or _from_uuid and _to_uuid)
  • The values of provided custom properties will be overwritten; the values of missing custom properties will be null.
  • The values of system properties (_id, _uuid, _from, _to, _from_uuid, _to_uuid) remain unchanged.

A new node is inserted when new _id or _uuid is provided, or when both _id and _uuid are missing.

A new edge is inserted when new _uuid is provided, or when _uuid is missing.

Example Graph

Run these UQLs row by row in an empty graphset to create this graph:

UQL
create().node_schema("user").edge_schema("follow")
create().node_property(@user, "name").node_property(@user, "age", int32).edge_property(@follow, "time", datetime)
Click to expand

Examples

Overwrite or Insert Nodes

UQL
insert().overwrite().into(@user).nodes([
  {_id: "U001", name: "John"},
  {_id: "U005", name: "Alice"},
  {age: 12}
]) as n
return n{*}
  • The first node with the provided _id U001 exists in the graph, so it is overwritten.
  • The second is a new node to be inserted, as the provided _id U005 does not exist in the graph.
  • The third is a new node to be inserted, as both _id and _uuid are missing.

Result:

_id
_uuidnameage
U0011Johnnull
U0055Alicenull
ULTIPA80000000000000066null12

Overwrite or Insert Edges

UQL
insert().overwrite().into(@follow).edges([
  {_uuid: 1, _from: "U004", _to: "U001"},
  {_uuid: 4, _from: "U002", _to: "U003"},
  {_from: "U002", _to: "U001", time: "2023-9-6"}
]) as e
return e{*}
  • The first edge with the provided _uuid 1, _from U004, and _to U001 exists in the graph, so it's overwritten.
  • The second is a new edge to be inserted, as the provided _uuid 4 does not exist in the graph.
  • The third is a new edge to be inserted, as _uuid is missing.

Result:

_uuid_from_to
_from_uuid
_to_uuid
time
1U004U00141null
4U002U00323null
5U002U001212023-09-06 00:00:00

Common Reasons for Failures

  • Overwriting fails when the specified existing nodes or edges do not belong to the given schema.
  • Node overwriting or insertion fails when both _id and _uuid are provided, one of their values exists in the graph while the other one does not.
  • Node overwriting or insertion fails when _id and _uuid are provided, they both exist in the graph but they don't match.
  • Edge overwriting or insertion fails when the start or end node is not specified.
  • Edge overwriting or insertion fails when the specified start or end node does not exist in the graph.
  • Edge overwriting fails when the given existing _uuid does not match the given start and end nodes.