Important
Self-managed SingleStore will soon transition from version 9.1 RC to version 10. This new semantic versioning scheme will provide SingleStore with finer control over engine and feature releases that were not possible with the current versioning scheme.
In the interim, SingleStore 9.1 RC can be used to preview, evaluate, and provide feedback on the new and upcoming features in SingleStore 10 prior to its general availability. Ahead of this transition, SingleStore 9.0 is recommended for production workloads, which can later be upgraded to SingleStore 10.
BSON_ COMPARE
On this page
The BSON_ function compares two BSON values of similar types.
SingleStore uses the same comparison/sort order for BSON types as MongoDB®.
Syntax
BSON_COMPARE(<input1>, <input2>)Arguments
<input1>, <input2>: Any valid BSON value or an expression that evaluates to a valid BSON value.
Return Type
BSON_ returns the following values:
|
Comparison |
Output |
|---|---|
|
|
0 |
|
|
-1 |
|
|
1 |
Remarks
BSON_ returns NULL for cross-type comparisons.
Examples
Note:The following examples explicitly cast string to BSON for clarity.
Here are a few examples of valid BSON value comparisons:
SELECT BSON_COMPARE('"string"':>BSON,'"string"':>BSON) AS Result;
+--------+
| Result |
+--------+
| 0 |
+--------+SELECT BSON_COMPARE('{"$oid":"641044fd4542e7dc53758df9"}':>BSON,'{"$oid":"641044fd4542e7dc53758df9"}':>BSON) AS Result;
+--------+
| Result |
+--------+
| 0 |
+--------+SELECT BSON_COMPARE('{"$numberLong":"99991241"}':>BSON, 99991241:>BSON) AS Result;
+--------+
| Result |
+--------+
| 0 |
+--------+SELECT BSON_COMPARE('{"$numberLong":"99991241"}':>BSON, '{"$numberDecimal":"211"}':>BSON) AS Result;
+--------+
| Result |
+--------+
| 1 |
+--------+SELECT BSON_COMPARE('null':>BSON,'null':>BSON) AS Result;
+--------+
| Result |
+--------+
| 0 |
+--------+The following examples return NULL because of cross-type value comparisons:
SELECT BSON_COMPARE('{"$numberLong":"99991241"}':>BSON, '"99991241"':>BSON) AS Result;
+--------+
| Result |
+--------+
| NULL |
+--------+SELECT BSON_COMPARE('{"$date":"2023-03-14T09:48:10.720Z"}':>BSON, '"2023-03-14T09:48:10.720Z"':>BSON) AS Result;
+--------+
| Result |
+--------+
| NULL |
+--------+Last modified: