Operators
Arithmetic operator expressions allow computation of new values. Attributes are treated as pure values when used in an arithmetic operator expression.
Quick reference
| Precedence | Operator | Name |
|---|---|---|
1 |
|
exponentiation (power) |
2 |
|
multiplication |
2 |
|
division |
2 |
|
modulo (remainder) |
3 |
|
addition |
3 |
|
subtraction |
Parentheses (()) may be used to override the precedence. The sub-expressions in parentheses are always evaluated first.
(1 + 2) * 3 == 9
Built-in functions
TypeQL provides several built-in functions for common mathematical and list operations:
Mathematical functions
round(x)-
Returns the provided numeric argument rounded to the nearest integer. If the value is half-way between two integers, rounds to the nearest even integer.
round(3.7) == 4
round(3.2) == 3
round(-3.7) == -4
round(3.5) == 4
round(4.5) == 4
ceil(x)-
Returns the provided numeric argument rounded to the nearest greater integer (ceiling).
ceil(3.2) == 4
ceil(3.7) == 4
ceil(-3.2) == -3
floor(x)-
Returns the provided numeric argument rounded to the nearest lesser integer (floor).
floor(3.2) == 3
floor(3.7) == 3
floor(-3.2) == -4
abs(x)-
Returns the absolute value of the provided numeric argument.
abs(5) == 5
abs(-5) == 5
abs(0) == 0
Comparison functions
min(x, y)-
Returns the minimum value of the two provided numeric arguments.
min(10, 12) == 10
min(3.5, 2.1) == 2.1
min(-5, -3) == -5
max(x, y)-
Returns the maximum value of the two provided numeric arguments.
max(10, 12) == 12
max(3.5, 2.1) == 3.5
max(-5, -3) == -3
String functions
len(x)-
Returns the length of the provided string argument in code points (Unicode Scalar Values).
len("hello") == 5
len("") == 0
len("こんにちは") == 5
len("⭐") == 1
len("❤️🔥") == 4
Concept functions
iid(x)-
Returns the internal ID of the provided instance argument as a string. The result is intended to be used in an
iidpredicate in future queries to uniquely identify the instance.iid()is mainly intended for use infetchqueries to uniquely identify the instance. It is not typically needed in other query types, as the IID is available directly in the result rows.
iid($x) == "0x1e0000000000000000001f"
label(t)-
Returns the label of the provided type argument as a string.
label($x) == "person"