UltipaDocs
Try Playground
  • Introduction
  • Terminologies
    • Graphset
    • Schema
    • Property
    • Constraints
    • Insert
    • Overwrite or Insert
    • Upsert
    • Update
    • Delete
    • Find Nodes
    • Find Edges
      • AB
      • Autonet
      • Spread
      • Path Template
      • K-Hop
      • K-Hop Template
    • GROUP BY
    • ORDER BY
    • SKIP
    • LIMIT
    • WHERE
    • RETURN
    • WITH
    • UNCOLLECT
    • UNION
    • UNION ALL
    • CALL
    • All Functions
    • Path Functions
    • Aggregate Functions
    • Mathematical Functions
    • Trigonometric Functions
    • String Functions
    • List Functions
    • Datetime Functions
    • Spatial Functions
    • Table Functions
    • Null Functions
    • Type Conversion Functions
  • Operators
  • Expressions
    • Index
    • Full-text Index
    • Vector Index
    • Cache
    • Overview
    • Managing HDC Graphs
    • HDC Graph Queries
    • Process
    • Job
    • Execution Plan
    • Alias
    • Filter
    • Values and Types
    • Data Flow in Queries
    • Comments
    • Reserved Words
  • Access Control
  1. Docs
  2. /
  3. UQL

Operators

All Operators

Category
Operators
Schema Reference@
Property Reference.
Logical Operators&&, `
Arithmetic Operators+, -, *, /, %
Comparison Operators=, !=, >, <, >=, <=, <>, <=>, =~
String OperatorsString Concatenation: +
String Matching: contains
List OperatorsList Construction: []
Elements Accessing: []
Membership Checking: in, nin
DeduplicationDISTINCT
Null Predicatesis null, is not null
Precedence Control()

Schema Reference

The @ allows you to reference the schema of a node or an edge.

UQL
find().nodes() as n
return n.@ limit 10
UQL
find().edges({@links}) as e
return e

Property Reference

The . (period) allows you to reference a property of a node or an edge.

UQL
find().nodes() as n
return n._id limit 10
UQL
n({@account.level > 3}).e().n() as p
return p

Logical Operators

And

Combines two or more conditions in a way that all of them must be true for the entire expression to evaluate to true.

Truth table for the && (and) operator:

&&TrueFalse
TrueTrueFalse
FalseFalseFalse

This query returns users whose age exceeds 30 and incomeGroup equals to 4:

UQL
find().nodes({@User}) as n
where n.age > 30 && n.incomeGroup == 4
return n

Or

Combines two or more conditions where only one of them needs to be true for the entire expression to evaluate to true.

Truth table for the || (or) operator:

||TrueFalse
TrueTrueTrue
FalseTrueFalse

This query returns users whose age exceeds 30, or incomeGroup equals to 4:

UQL
find().nodes({@User}) as n
where n.age > 30 || n.incomeGroup == 4
return n

Xor

Combines two or more conditions by evaluating two conditions at a time. For two conditions, the result is true only if exactly one of the conditions is true. If both are true or both are false, the result is false. When applied to multiple conditions, xor first evaluates the result of the first two conditions, then compares that result with the next condition, continuing this process until all conditions are checked.

Truth table for the xor operator:

xorTrueFalse
TrueFalseTrue
FalseTrueFalse

This query returns users whose age exceeds 30, or incomeGroup equals to 4, but excludes users who meet both criteria:

UQL
find().nodes({@User}) as n
where n.age > 30 xor n.incomeGroup == 4
return n

Not

Negates a condition, returning true if the specified condition is false and vice versa.

Truth table for the ! (not) operator:

!
TrueFalse
FalseTrue

This query returns users whose age is not 30:

UQL
find().nodes({@User}) as n
where !(n.age == 30)
return n

Arithmetic Operators

Performs mathematical operations on numerical values. UQL supports the following arithmetic operators:

  • Addition: +
  • Subtraction: -
  • Multiplication: *
  • Division: /
  • Modulus: %
UQL
return (2+8)%3

Result:

(2+8)%3
1

Comparison Operators

Compares two values or expressions and returns true or false. UQL supports the following comparison operators:

  • Equal to: ==
  • Not equal to: !=
  • Greater than: >
  • Less than: <
  • Greater than or equal to: >=
  • Less than or equal to: <=
  • Between: <>
  • Between or equal to: <=>
  • Regular match: =~

This query returns users whose age is not 30:

UQL
find().nodes({@User}) as n
where n.age != 30
return n

This query returns users whose age is between 25 to 35, exclusive of both endpoints (25 and 35):

UQL
find().nodes({@User.age <> [25, 35]}) as n
return n

This query returns users whose age is between 25 to 35, inclusive of both endpoints (25 and 35):

UQL
find().nodes({@User.age <=> [25, 35]}) as n
return n

This query returns users whose email is in the format of [email protected] or [email protected]:

UQL
find().nodes({@User.email =~ "^[a-zA-Z0-9_.-]+@[a-zA-Z0-9]+\.(com|cn)$"}) as n
return n

String Operators

String Concatenation

The + combines multiple strings into a single string by merging the characters of each string in order.

UQL
return "data" + "base"

Result:

"data" + "base"
database

String Matching

The contains operator checks if one string contains another (case-sensitive).

This query returns user nodes whose aboutMe contains "graph database":

UQL
find().nodes({@user.aboutMe contains "graph database"}) as n
return n

You can transform all letters to upper or lower cases for case-insensitive matching:

UQL
find().nodes({lower(@user.aboutMe) contains "graph database"}) as n
return n

The contains operator is also used to match the specified keywords with tokens of a full-text index (precise or fuzzy match). See Using Full-text Indexes.

This query finds nodes using the full-text index prodDesc where their tokens include "graph" and "database":

UQL
find().nodes({~prodDesc contains "graph database"}) as n
return n

List Operators

List Construction

The [] can create a list by placing comma-separated elements inside.

UQL
with [1,2,3] as items
return items

Result:

items
[1,2,3]

The [] can also construct a nested list:

UQL
with [[1,2],[2,3]] as items
return items

Result:

items
[[1,2],[2,3]]

Elements Accessing

The [] can access elements within a list by their indexes. Lists use 0-based indexing, meaning the first element is at index 0.

UQL
with ["a", 1, "b"] as items
return items[0]

Result:

items[0]
a

Membership Checking

The in checks whether a specified element exists within a list. Conversely, the nin checks whether a specified element does not exist within a list.

This query returns nodes whose _id can be found in the list of ["U01", "U02"]:

UQL
find().nodes({_id in ["U01", "U02"]}) as n
return n

This query returns nodes whose _id cannot be found in the list of ["U01", "U02"]:

UQL
find().nodes({_id nin ["U01", "U02"]}) as n
return n

Deduplication

The distinct ensures that only unique values are included.

This query returns distinct age values of users:

UQL
find().nodes({@User}) as n
return distinct n.age

Null Predicates

Specifies a test for a null value. UQL supports the following null predicates:

  • is null
  • is not null

This query retrieves the title of each @Paper node if the value is not null; otherwise, it returns the message TITLE NOT FOUND.

UQL
find().nodes({@Paper}) as n
return case
  when n.title is not null then n.title
  else "TITLE NOT FOUND"
end