UltipaDocs
Try Playground
  • Introduction
  • GQL vs Other Languages
    • Overview
    • Node and Edge Patterns
    • Path Patterns
    • Quantified Paths
    • Shortest Paths
    • Graph Patterns
    • Overview
    • Closed 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
    • Type Conversion Functions
    • Table Functions
    • AI & Vector Functions
    • Database Functions
  • Operators
  • Predicates
  • Expressions
    • Index
    • Full-text Index
    • Vector Index
  • Transactions
  • Triggers
  • Query Management
  • Backup and Restore
    • Variables
    • Values and Types
    • Comments
    • Reserved Words
    • Syntactic Notation
  • GQL Conformance
  1. Docs
  2. /
  3. ISO GQL
  4. /
  5. Data Modification

SET

Overview

The SET statement allows you to set properties and labels on nodes and edges. These nodes or edges must first be retrieved using the MATCH statement.

Note:

  • In typed graphs, the schema of a node or edge is immutable.
  • The unique identifiers _id and _uuid are immutable.

Typed Graph

Example Graph

CREATE GRAPH myGraph {
  NODE User ({name STRING, gender STRING}),
  NODE Club (),
  EDGE Follows ()-[{createdOn DATE}]->(),
  EDGE Joins ()-[{memberNo INT32}]->()
}

Updating a Property

To update the value of each specified property:

GQL
MATCH (n:User {name: 'rowlock'})-[e:Follows]->(:User {name: 'Brainy'})
SET n.gender = 'male', e.createdOn = '2024-01-07'
RETURN n.gender, e.createdOn

Removing a Property

To remove the values of specified properties by setting them to null:

GQL
MATCH (n:User {name: 'mochaeach'})
SET n.gender = null

Overwriting All Properties

You can overwrite all property values of a node or edge using a record. Any property included in the record will be updated, while all other properties will be set to null.

GQL
MATCH (n:User {name: 'purplechalk'})
SET n = {name: 'MasterSwift'}
RETURN n

To remove all property values by setting an empty record:

GQL
MATCH (n:User {name: 'rowlock'})
SET n = {}
RETURN n

Mismatched Value Type

If the provided value does not match the property's value type and cannot be converted, the property will be assigned its default value based on the property value type.

For example, if you update memberNo (UINT64 type) with a string value, memberNo will be automatically set to 0:

GQL
MATCH ()-[e:Joins]->()
SET e.memberNo = 'm2'

Open Graph

Example Graph

CREATE GRAPH myGraph ANY

Adding Labels

To add a label to a node:

GQL
MATCH (n:User {name: 'rowlock'})
SET n:Person

To add two labels to a node:

GQL
MATCH (n:User {name: 'rowlock'})
SET n:Player, n:Employee
NOTE

To remove labels from nodes or edges, use the REMOVE statement.

Updating a Property

To update the value of each specified property:

GQL
MATCH (n:User {name: 'rowlock'})-[e:Follows]->(:User {name: 'Brainy'})
SET n.gender = 'male', e.createdOn = date('2024-01-07')
RETURN n.gender, e.createdOn

Replace All Properties

You can replace all properties of a node or edge using a record.

To replace all property values:

GQL
MATCH (n:User {name: 'purplechalk'})
SET n = {username: 'MasterSwift', age: 36}
RETURN n