BSON_COMPARE

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_COMPARE() returns the following values:

Comparison

Output

<input1> equals <input2>

0

<input1> is less than <input2>

-1

<input1> is greater than <input2>

1

Remarks

BSON_COMPARE() returns NULL for cross-type comparisons.

Examples

Note:The following examples explicitly cast string to BSON for clarity. Similarly, the output is cast to JSON.

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: May 8, 2024

Was this article helpful?

Verification instructions

Note: You must install cosign to verify the authenticity of the SingleStore file.

Use the following steps to verify the authenticity of singlestoredb-server, singlestoredb-toolbox, singlestoredb-studio, and singlestore-client SingleStore files that have been downloaded.

You may perform the following steps on any computer that can run cosign, such as the main deployment host of the cluster.

  1. (Optional) Run the following command to view the associated signature files.

    curl undefined
  2. Download the signature file from the SingleStore release server.

    • Option 1: Click the Download Signature button next to the SingleStore file.

    • Option 2: Copy and paste the following URL into the address bar of your browser and save the signature file.

    • Option 3: Run the following command to download the signature file.

      curl -O undefined
  3. After the signature file has been downloaded, run the following command to verify the authenticity of the SingleStore file.

    echo -n undefined |
    cosign verify-blob --certificate-oidc-issuer https://oidc.eks.us-east-1.amazonaws.com/id/CCDCDBA1379A5596AB5B2E46DCA385BC \
    --certificate-identity https://kubernetes.io/namespaces/freya-production/serviceaccounts/job-worker \
    --bundle undefined \
    --new-bundle-format -
    Verified OK