Comparators
|
This documentation is not current - it is for TypeDB 2.x, which is no longer supported. View the documentation for TypeDB 3.x: |
Behavior
Comparing operators or comparators can be used in a match clause of a TypeQL query
to compare by value two variables or a variable with a static value.
You can use both concept variables and value variables with comparators.
A concept variable must represent an attribute, since only attributes have values.
Comparators are always considered to return True. That sets a constraint on values that can be assigned to a variable used in a statement with a comparator.
The following operators are supported for comparing values: ==, !=, >, >=, <, and <=.
Equality comparator
For this example, use a database with the IAM schema and sample data loaded.
Use the double equal sign (==) to declare equality between two values.
For example, let’s find all files with a size attribute of value equal to 100:
match
$file isa file,
has path $filepath,
has size-kb $size;
$size == 100;
get $filepath;
|
Since version |
Inequality comparator
For this example, use a database with the IAM schema and sample data loaded.
Use the exclamation mark with a single equal sign (!=) to declare inequality between two values.
For example, to find sizes for all files, that have filepath attribute of any value except the README.md:
match
$file isa file,
has path $filepath,
has size-kb $size;
$filepath != "README.md";
get $size;
Greater than / Less than comparators
For this example, use a database with the IAM schema and sample data loaded.
Use the greater than sign (>) to declare the value/variable on the left from it as strictly greater
than the one on the right from it.
For a relaxed comparison, use the "greater than or equal" sign (>=).
Use the less than sign (<) to declare the value/variable on the left from it as strictly less
than the one on the right from it.
For a relaxed comparison, use the "less than or equal" sign (<=).
For example, use the following query to find all files that have an attribute of the size type
and value less than or equal to 50.
match
$file isa file,
has path $filepath,
has size-kb $size;
$size ≤ 100;
get $filepath;