BSON_UNWIND

Converts a BSON document to a PSQL array.

Syntax

BSON_UNWIND(<input>)

Argument

<input>: A valid BSON type or array, or an expression that evaluates to a valid BSON type or array.

Return Type

A PSQL array.

Remarks

  • If the input is a valid non-empty BSON array, a PSQL array is returned.

  • If the input is a BSON type other than the array, it is mapped to the PSQL array as a single element.

  • BSON_UNWIND() returns NULL if the input is a SQL NULL, BSON NULL, BSON undefined, or an empty BSON array.

Examples

Note: The following examples explicitly cast string to BSON for clarity. Similarly, the output is cast to JSON. The TABLE() command is used to convert the PSQL array to a set of rows.

The following example adds the BSON input as a single element in the array because the input is not a BSON array.

SELECT table_col:>JSON AS Result
FROM TABLE(BSON_UNWIND('{"field1":"string value","field2":[12,3,1331,"arr"],"field3":true,"field4":null}':>BSON));
+----------------------------------------------------------------------------------+
| Result                                                                           |
+----------------------------------------------------------------------------------+
| {"field1":"string value","field2":[12,3,1331,"arr"],"field3":true,"field4":null} |
+----------------------------------------------------------------------------------+

The following example converts a BSON array to a PSQL array and returns the result as a set of rows, where each row represents an element in the array.

SELECT table_col:>JSON AS Result FROM TABLE(BSON_UNWIND('[1,true,null,"a string",2,3,4,5,{"a":"abc","b":[]},{}]':>BSON));
+--------------------+
| Result             |
+--------------------+
| 1                  |
| true               |
| null               |
| "a string"         |
| 2                  |
| 3                  |
| 4                  |
| 5                  |
| {"a":"abc","b":[]} |
| {}                 |
+--------------------+

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