UltipaDocs
Products
Solutions
Resources
Company
Start Free Trial
UltipaDocs
Start Free Trial
  • Introduction
  • GQL vs Other Languages
    • Overview
    • Node and Edge Patterns
    • Path Patterns
    • Quantified Paths
    • Questioned Paths
    • Shortest Paths
    • Graph Patterns
    • Overview
    • Open Graph
    • Closed Graph
    • Constraints
    • Unique Identifiers
    • INSERT
    • INSERT OVERWRITE
    • 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
    • Element Functions
    • Path Functions
    • Aggregate Functions
    • Mathematical Functions
    • Trigonometric Functions
    • String Functions
    • List Functions
    • Datetime Functions
    • Spatial Functions
    • Null Functions
    • Utility Functions
    • Type Conversion Functions
    • Table Functions
    • AI & Vector Functions
    • Database Functions
  • Operators
  • Predicates
    • CASE
    • LET Value Expression
    • Value Query Expression
    • List Comprehension
    • 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. Graph Management

Constraints

Overview

Constraints enforce additional rules on the node and edge properties in the graph. Any attempt to insert or update data that violates these rules will result in an error.

Ultipa supports the following constraints in closed graphs:

  • NOT NULL: Ensures that a property never contains null values.
  • UNIQUE: Ensures that a property contains no duplicate values.

Showing Constraints

Show all constraints in the current graph:

GQL
SHOW CONSTRAINTS

Show node constraints in the current graph:

GQL
SHOW NODE CONSTRAINTS

Show edge constraints in the current graph:

GQL
SHOW EDGE CONSTRAINTS

Each constraint provides the following metadata:

Field
Description
entity_typeNODE or EDGE.
typeThe node or edge type where the constraint applies.
propertyThe property where the constraint applies.
constraint_typeConstraint type (NOT NULL, UNIQUE).

Creating Constraints

You can define constraints when creating a closed graph, creating a graph type, or within an existing closed graph.

Note that creating a constraint in a large graph may take time, as the system must scan all existing data to ensure compliance. The creation will fail if any existing data violates the constraint.

NOT NULL

The NOT NULL constraint ensures that a property never contains null values.

Create a NOT NULL constraint on the property name of node type User:

GQL
ALTER NODE User ADD CONSTRAINT NOT NULL ON name

Create a NOT NULL constraint on the property createdOn of edge type KNOWS:

GQL
ALTER EDGE KNOWS ADD CONSTRAINT NOT NULL ON createdOn

The NOT NULL constraint can only be successfully created when no null values exist in the specified property.

You can apply the NOT NULL constraint to any property when creating a closed graph:

GQL
CREATE GRAPH myGraph {
  NODE User ({name STRING NOT NULL, age UINT32}),
  EDGE KNOWS ()-[{createdOn TIMESTAMP NOT NULL, eid STRING}]->()
}

You can also apply the NOT NULL constraint to any property when creating a graph type:

GQL
CREATE GRAPH TYPE gType {
  NODE User ({name STRING NOT NULL, age UINT32}),
  EDGE KNOWS ()-[{createdOn TIMESTAMP NOT NULL, eid STRING}]->()
}

UNIQUE

The UNIQUE constraint ensures that a property contains no duplicate values.

Create a UNIQUE constraint on the property name of node type User:

GQL
ALTER NODE User ADD CONSTRAINT UNIQUE ON name

Create a UNIQUE constraint on the property eid of edge type KNOWS:

GQL
ALTER EDGE KNOWS ADD CONSTRAINT UNIQUE ON eid

The UNIQUE constraint can only be successfully created when no duplicate values exist in the specified property.

You can apply the UNIQUE constraint to any property when creating a closed graph:

GQL
CREATE GRAPH myGraph {
  NODE User ({name STRING UNIQUE, age UINT32}),
  EDGE KNOWS ()-[{createdOn TIMESTAMP, eid STRING UNIQUE}]->()
}

You can also apply the UNIQUE constraint to any property when creating a graph type:

GQL
CREATE GRAPH TYPE gType {
  NODE User ({name STRING UNIQUE, age UINT32}),
  EDGE KNOWS ()-[{createdOn TIMESTAMP, eid STRING UNIQUE}]->()
}

Dropping Constraints

Drop the NOT NULL constraint on the name property of node type User from the current graph:

GQL
ALTER NODE User DROP CONSTRAINT NOT NULL ON name

Drop the UNIQUE constraint on the eid property of edge type KNOWS from the current graph:

GQL
ALTER EDGE KNOWS DROP CONSTRAINT UNIQUE ON eid