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

Insert

Overview

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

Syntax

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

// Insert edges
insert().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.

Inserting nodes:

  • No property is mandatory to be provided.
  • If the unique identifier property _id or _uuid is missing, its value will be generated by the system.
  • The values of missing custom properties will be null.

Inserting edges:

  • The properties _from and _to (or _from_uuid and _to_uuid) are mandatory to be provided to specify the start and end nodes of the edge. Other properties are optional.
  • If the unique identifier property _uuid is missing, its value will be automatically generated by the system.
  • The values of missing custom properties will be null.

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

Insert Single Node

UQL
insert().into(@user).nodes({_id: "U005", name: "Alice"})

A new node is inserted with the following properties:

_id_uuidnameage
U0055Alicenull

Insert Single Edge

UQL
insert().into(@follow).edges({_from: "U002", _to: "U001", time: "2023-8-9"})

A new edge is inserted with the following properties:

_uuid_from_to
_from_uuid
_to_uuid
time
4U002U001212023-08-09 00:00:00

Insert Multiple Nodes

UQL
insert().into(@user).nodes([
  {name: "Lee", age: 12},
  {_uuid: 10, name: "Alex"},
  {}
])

Three new nodes are inserted with the following properties:

_id
_uuidnameage
ULTIPA80000000000000096Lee12
ULTIPA800000000000000510Alexnull
ULTIPA800000000000000B7nullnull

Insert Multiple Edges

UQL
insert().into(@follow).edges([
  {_from_uuid: 1, _to_uuid: 2},
  {_uuid: 9, _from: "U004", _to: "U003", time: "2023-9-10"},
  {_from: "U002", _to: "U003"}
])

Three new edges are inserted with the following properties:

_uuid_from_to
_from_uuid
_to_uuid
time
5U001U00212null
9U004U003432023-09-10 00:00:00
6U002U00323null

Return Inserted Data

UQL
insert().into(@user).nodes([
  {_id: "U006", name: "Joy"},
  {_id: "U007", age: 41}
]) as n
return n{*}

Result:

_id_uuidnameage
U0068Joynull
U0079null41

Provide Point-Type Value

Use the point() function to specify the value of a point-type property.

UQL
insert().into(@city).nodes([
  { location: point({latitude: 132.1, longitude: -1.5}) }
])

Provide Blob-Type Value

Use the castToRaw() function to specify the value of a blob-type property.

UQL
insert().into(@city).nodes([
  {profile_img: castToRaw("data:image/png;base64,iVBO0KGf8/9hAHNCSVQI=")}
])

Provide List-Type Value

Provide a list with elements enclosed in [ ] and separated with ,. The data type of each element should correspond to the type of the list.

Here's an example of inserting a node while providing the value for a list-type (float[]) property ratings:

UQL
insert().into(@city).nodes([
  {ratings: [3.2, 6.7, 5.6, 5.6]}
])

Provide Set-Type Value

Provide a set with elements enclosed in [ ] and separated with ,. The data type of each element should correspond to the type of the set.

Here's an example of inserting a node while providing the value for a set-type (set(string)) property tags:

UQL
insert().into(@city).nodes([
  {tags: ["hot", "art", "food"]}
])

Common Reasons for Failures

  • Insertion fails when any provided values of unique identifier properties (_id, _uuid) already exist in the graph.
  • Edge insertion fails when the specified start node or end node does not exist in the graph.
  • Edge insertion fails when the start node or end node is not specified.