All Operators
Category |
Operators |
---|---|
Schema Reference | @ |
Property Reference | . |
Logical Operators | && , ` |
Arithmetic Operators | + , - , * , / , % |
Comparison Operators | = , != , > , < , >= , <= , <> , <=> , =~ , in , nin |
String Operators | String Concatenation: + Contains: contains Contains (Full-text Index): contains |
List Operators | List Construction: [] Elements Accessing: [] Membership Checking: in , nin |
Deduplication | DISTINCT |
Null Predicates | is null , is not null |
Precedence Control | () |
Schema Reference
The @
allows you to reference the schema of a node or an edge.
find().nodes() as n
return n.@ limit 10
find().edges({@links}) as e
return e
Property Reference
The .
(period) allows you to reference a property of a node or an edge.
find().nodes() as n
return n._id limit 10
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:
&& |
True | False |
---|---|---|
True | True | False |
False | False | False |
This query returns users whose age
exceeds 30 and incomeGroup
equals to 4:
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:
|| |
True | False |
---|---|---|
True | True | True |
False | True | False |
This query returns users whose age
exceeds 30, or incomeGroup
equals to 4:
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:
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:
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:
! |
True | False |
---|---|---|
False | True |
This query returns users whose age
is not 30:
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:
%
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:
=~
- Belong to:
in
(See Membership Checking) - Not belong to:
nin
(See Membership Checking)
This query returns users whose age
is not 30:
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):
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):
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]
:
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.
return "data" + "base"
Result:
"data" + "base" |
---|
database |
Contains
The contains
checks if one string contains another as a substring.
return "Graph Database@d134" contains "graph"
Result:
"Graph Database@d134" contains "graph" |
---|
0 |
This query returns user whose aboutMe
contains "graph database":
find().nodes({@User.aboutMe contains "graph database"}) as n
return n
Contains (Full-text Index)
The contains
, when used with a full-text index, checks if its segmented tokens contain all the specified keywords.
To find nodes using the full-text index prodDesc
where tokens include both "graph" and "database":
find().nodes({~prodDesc contains "graph database"}) as n
return n
For more examples and detailed explanations, see Full-text Index.
List Operators
List Construction
The []
can create a list by placing comma-separated elements inside.
with [1,2,3] as items
return items
Result:
items |
---|
[1,2,3] |
The []
can also construct a nested list:
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
.
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"]
:
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"]
:
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:
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
.
find().nodes({@Paper}) as n
return case
when n.title is not null then n.title
else "TITLE NOT FOUND"
end