Back to top
  Back to overview

Operators

SurrealDB offers a large number of operators for value comparison.

Operator Description
= Check whether two values are equal
!= Check whether two values are not equal
== Check whether two values are exactly equal
?= Check whether any value in a set is equal to a value
*= Check whether all values in a set are equal to a value
~ Compare two values for equality using fuzzy matching
!~ Compare two values for inequality using fuzzy matching
?~ Check whether any value in a set is equal to a value using fuzzy matching
*~ Check whether all values in a set are equal to a value using fuzzy matching
< Check whether a value is less than another value
<= Check whether a value is less than or equal to another value
> Check whether a value is greater than another value
>= Check whether a value is greater than or equal to another value
+ Add two values together
- Subtract a value from another value
* Multiply two values together
/ Divide a value by another value
&& Checks whether two values are truthy
|| Checks whether either of two values is truthy
AND Checks whether two values are truthy
OR Checks whether either of two values is truthy
IS Check whether two values are equal
IS NOT Check whether two values are not equal
CONTAINS or Checks whether a value contains another value
CONTAINSNOT or Checks whether a value does not contain another value
CONTAINSALL or Checks whether a value contains all other values
CONTAINSANY or Checks whether a value contains any other value
CONTAINSNONE or Checks whether a value contains none of the following values
INSIDE or Checks whether a value is contained within another value
NOTINSIDE or Checks whether a value is not contained within another value
ALLINSIDE or Checks whether all values are contained within other values
ANYINSIDE or Checks whether any value is contained within other values
NONEINSIDE or Checks whether no value is contained within other values
OUTSIDE Checks whether a geometry type is outside of another geometry type
INTERSECTS Checks whether a geometry type intersects another geometry type

=

Check whether two values are equal.

SELECT * FROM true = "true";
true
SELECT * FROM 10 = "10";
true
SELECT * FROM 10 = 10.00;
true
SELECT * FROM 10 = "10.3";
false
SELECT * FROM [1, 2, 3] = [1, 2, 3];
true
SELECT * FROM [1, 2, 3] = [1, 2, 3, 4];
false
SELECT * FROM { this: "object" } = { this: "object" };
true
SELECT * FROM { this: "object" } = { another: "object" };
false

!=

Check whether two values are not equal.

SELECT * FROM 10 != "15";
true
SELECT * FROM 10 != "test";
true
SELECT * FROM [1, 2, 3] != [3, 4, 5];
true

==

Check whether two values are exact. This operator also checks that each value has the same type.

SELECT * FROM 10 == 10;
true
SELECT * FROM 10 == "10";
false
SELECT * FROM true == "true";
false

?=

Check whether any value in an array equals another value.

SELECT * FROM [10, 15, 20] ?= 10;
true

*=

Check whether all values in an array equals another value.

SELECT * FROM [10, 10, 10] *= 10;
true

<

Check whether a value is less than another value.

SELECT * FROM 10 < 15;
true

<=

Check whether a value is less than or equal to another value.

SELECT * FROM 10 <= 15;
true

>

Check whether a value is less than another value.

SELECT * FROM 15 > 10;
true

>=

Check whether a value is less than or equal to another value.

SELECT * FROM 15 >= 10;
true

+

Adds a value to another value.

SELECT * FROM 10 + 10;
20
SELECT * FROM "test" + " " + "this";
"test this"
SELECT * FROM 13h + 30m;
"13h30m"
SELECT * FROM "2021-11-01" + 1w;
"2021-11-08T00:00:00Z"

-

Subtracts a value from another value.

SELECT * FROM 20 - 10;
10
SELECT * FROM 2m - 1m;
"60s"
SELECT * FROM "2021-11-01" - 1w;
"2021-10-25T00:00:00Z"

*

Multiplies a value by another value.

SELECT * FROM 20 * 2;
40

/

Divides a value with another value.

SELECT * FROM 20 / 2;
10

&&

Checks whether two values are truthy.

SELECT * FROM 10 && 20 && 30;
10

||

Checks whether either of two values are truthy.

SELECT * FROM 0 || false || 10;
10

AND

Checks whether two values are truthy.

SELECT * FROM 10 AND 20 AND 30;
10

OR

Checks whether either of two values are truthy.

SELECT * FROM 0 OR false OR 10;
10

IS

Check whether two values are equal.

SELECT * FROM 10 IS "10";
true

IS NOT

Check whether two values are not equal.

SELECT * FROM 10 IS NOT "15";
true

CONTAINS or

Check whether a value contains another value.

SELECT * FROM [10, 20, 30] CONTAINS 10;
true
SELECT * FROM "this is some text" CONTAINS "text";
true
SELECT * FROM {
	type: "Polygon",
	coordinates: [[
		[-0.38314819, 51.37692386], [0.1785278, 51.37692386],
		[0.1785278, 51.61460570], [-0.38314819, 51.61460570],
		[-0.38314819, 51.37692386]
	]]
} CONTAINS (-0.118092, 51.509865);
true

CONTAINSNOT or

Check whether a value does not contain another value.

SELECT * FROM [10, 20, 30] CONTAINSNOT 15;
true
SELECT * FROM "this is some text" CONTAINSNOT "other";
true
SELECT * FROM {
	type: "Polygon",
	coordinates: [[
		[-0.38314819, 51.37692386], [0.1785278, 51.37692386],
		[0.1785278, 51.61460570], [-0.38314819, 51.61460570],
		[-0.38314819, 51.37692386]
	]]
} CONTAINSNOT (-0.518092, 53.509865);
true

CONTAINSALL or

Check whether a value contains all of multiple values.

SELECT * FROM [10, 20, 30] CONTAINSALL [10, 20, 10];
true

CONTAINSANY or

Check whether a value contains any of multiple values.

SELECT * FROM [10, 20, 30] CONTAINSANY [10, 15, 25];
true

CONTAINSNONE or

Check whether a value does not contain any of multiple values.

SELECT * FROM [10, 20, 30] CONTAINSNONE [15, 25, 35];
true

INSIDE or

Check whether a value is contained within another value.

SELECT * FROM 10 INSIDE [10, 20, 30];
true
SELECT * FROM "text" INSIDE "this is some text";
true
SELECT * FROM (-0.118092, 51.509865) INSIDE {
	type: "Polygon",
	coordinates: [[
		[-0.38314819, 51.37692386], [0.1785278, 51.37692386],
		[0.1785278, 51.61460570], [-0.38314819, 51.61460570],
		[-0.38314819, 51.37692386]
	]]
};
true

NOTINSIDE or

Check whether a value is not contained within another value.

SELECT * FROM 15 NOTINSIDE [10, 20, 30];
true
SELECT * FROM "other" NOTINSIDE "this is some text";
true
SELECT * FROM (-0.518092, 53.509865) NOTINSIDE {
	type: "Polygon",
	coordinates: [[
		[-0.38314819, 51.37692386], [0.1785278, 51.37692386],
		[0.1785278, 51.61460570], [-0.38314819, 51.61460570],
		[-0.38314819, 51.37692386]
	]]
};
true

ALLINSIDE or

Check whether all of multiple values are contained within another value.

SELECT * FROM [10, 20, 10] ALLINSIDE [10, 20, 30];
true

ANYINSIDE or

Check whether any of multiple values are contained within another value.

SELECT * FROM [10, 15, 25] ANYINSIDE [10, 20, 30];
true

NONEINSIDE or

Check whether none of multiple values are contained within another value.

SELECT * FROM [15, 25, 35] NONEINSIDE [10, 20, 30];
true

OUTSIDE

Check whether a geometry value is outside another geometry value.

SELECT * FROM (-0.518092, 53.509865) OUTSIDE {
	type: "Polygon",
	coordinates: [[
		[-0.38314819, 51.37692386], [0.1785278, 51.37692386],
		[0.1785278, 51.61460570], [-0.38314819, 51.61460570],
		[-0.38314819, 51.37692386]
	]]
};
true

INTERSECTS

Check whether a geometry value intersects annother geometry value.

SELECT * FROM {
	type: "Polygon",
	coordinates: [[
		[-0.38314819, 51.37692386], [0.1785278, 51.37692386],
		[0.1785278, 51.61460570], [-0.38314819, 51.61460570],
		[-0.38314819, 51.37692386]
	]]
} INTERSECTS {
	type: "Polygon",
	coordinates: [[
		[-0.11123657, 51.53160074], [-0.16925811, 51.51921169],
		[-0.11466979, 51.48223813], [-0.07381439, 51.51322956],
		[-0.11123657, 51.53160074]
	]]
};
true