Category | Operators |
|---|---|
| Schema Reference | @ |
| Property Reference | . |
| Logical Operators | &&, ` |
| Arithmetic Operators | +, -, *, /, % |
| Comparison Operators | =, !=, >, <, >=, <=, <>, <=>, =~ |
| String Operators | String Concatenation: +String Matching: contains |
| List Operators | List Construction: []Elements Accessing: []Membership Checking: in, nin |
| Deduplication | DISTINCT |
| Null Predicates | is null, is not null |
| Precedence Control | () |
The @ allows you to reference the schema of a node or an edge.
UQLfind().nodes() as n return n.@ limit 10
UQLfind().edges({@links}) as e return e
The . (period) allows you to reference a property of a node or an edge.
UQLfind().nodes() as n return n._id limit 10
UQLn({@account.level > 3}).e().n() as p return p
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:
&& | True | False |
|---|---|---|
| True | True | False |
| False | False | False |
This query returns users whose age exceeds 30 and incomeGroup equals to 4:
UQLfind().nodes({@User}) as n where n.age > 30 && n.incomeGroup == 4 return n
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:
|| | True | False |
|---|---|---|
| True | True | True |
| False | True | False |
This query returns users whose age exceeds 30, or incomeGroup equals to 4:
UQLfind().nodes({@User}) as n where n.age > 30 || n.incomeGroup == 4 return n
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:
xor | True | False |
|---|---|---|
| True | False | True |
| False | True | False |
This query returns users whose age exceeds 30, or incomeGroup equals to 4, but excludes users who meet both criteria:
UQLfind().nodes({@User}) as n where n.age > 30 xor n.incomeGroup == 4 return n
Negates a condition, returning true if the specified condition is false and vice versa.
Truth table for the ! (not) operator:
! | True | False |
|---|---|---|
| False | True |
This query returns users whose age is not 30:
UQLfind().nodes({@User}) as n where !(n.age == 30) return n
Performs mathematical operations on numerical values. UQL supports the following arithmetic operators:
+-*/%UQLreturn (2+8)%3
Result:
| (2+8)%3 |
|---|
| 1 |
Compares two values or expressions and returns true or false. UQL supports the following comparison operators:
==!=><>=<=<><=>=~This query returns users whose age is not 30:
UQLfind().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):
UQLfind().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):
UQLfind().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]:
UQLfind().nodes({@User.email =~ "^[a-zA-Z0-9_.-]+@[a-zA-Z0-9]+\.(com|cn)$"}) as n return n
The + combines multiple strings into a single string by merging the characters of each string in order.
UQLreturn "data" + "base"
Result:
| "data" + "base" |
|---|
| database |
The contains operator checks if one string contains another (case-sensitive).
This query returns user nodes whose aboutMe contains "graph database":
UQLfind().nodes({@user.aboutMe contains "graph database"}) as n return n
You can transform all letters to upper or lower cases for case-insensitive matching:
UQLfind().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":
UQLfind().nodes({~prodDesc contains "graph database"}) as n return n
The [] can create a list by placing comma-separated elements inside.
UQLwith [1,2,3] as items return items
Result:
| items |
|---|
| [1,2,3] |
The [] can also construct a nested list:
UQLwith [[1,2],[2,3]] as items return items
Result:
| items |
|---|
| [[1,2],[2,3]] |
The [] can access elements within a list by their indexes. Lists use 0-based indexing, meaning the first element is at index 0.
UQLwith ["a", 1, "b"] as items return items[0]
Result:
| items[0] |
|---|
| a |
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"]:
UQLfind().nodes({_id in ["U01", "U02"]}) as n return n
This query returns nodes whose _id cannot be found in the list of ["U01", "U02"]:
UQLfind().nodes({_id nin ["U01", "U02"]}) as n return n
The distinct ensures that only unique values are included.
This query returns distinct age values of users:
UQLfind().nodes({@User}) as n return distinct n.age
Specifies a test for a null value. UQL supports the following null predicates:
is nullis not nullThis query retrieves the title of each @Paper node if the value is not null; otherwise, it returns the message TITLE NOT FOUND.
UQLfind().nodes({@Paper}) as n return case when n.title is not null then n.title else "TITLE NOT FOUND" end