# BSON\_INPUT\_STREAM\_TO\_ARRAY

Converts a BSON array of documents or concatenated BSON documents to a PSQL Array.

## Syntax

```
BSON_INPUT_STREAM_TO_ARRAY(<input>)
```

## Arguments

* `input`: A valid BSON array, an expression that evaluates to a valid BSON array, or concatenated BSON documents.

## Return Type

A PSQL array.

## Examples

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

* Convert a BSON array:
  ```sql
  SELECT table_col:>JSON AS Result 
  FROM TABLE(BSON_INPUT_STREAM_TO_ARRAY('[{"a":1},{"b":2},{"c":3},{"d":4}]':>BSON));

  ```
  ```output

  +---------+
  | Result  |
  +---------+
  | {"a":1} |
  | {"b":2} |
  | {"c":3} |
  | {"d":4} |
  +---------+
  ```
  ```sql
  SELECT table_col:>JSON AS Result 
  FROM TABLE(BSON_INPUT_STREAM_TO_ARRAY('[{"a":1,"b":"abcdef","c":null},{"b":2,"e":{"f":{"g":[]}}},{"c":3},{}]':>JSON:>BSON));

  ```
  ```output

  +-------------------------------+
  | Result                        |
  +-------------------------------+
  | {"a":1,"b":"abcdef","c":null} |
  | {"b":2,"e":{"f":{"g":[]}}}    |
  | {"c":3}                       |
  | {}                            |
  +-------------------------------+
  ```
* Convert concatenated documents:
  ```sql
  SELECT table_col:>JSON AS Result 
  FROM TABLE(BSON_INPUT_STREAM_TO_ARRAY(x'0C00000010610001000000000C00000010620002000000000C00000010630003000000000C0000001064000400000000')) 
  AS Result;

  ```
  ```output

  +---------+
  | Result  |
  +---------+
  | {"a":1} |
  | {"b":2} |
  | {"c":3} |
  | {"d":4} |
  +---------+
  ```
  where, `x'0C00000010610001000000000C00000010620002000000000C00000010630003000000000C0000001064000400000000'` is a hex literal that is formed by concatenating the following BSON documents:
  | Document  | Hex Representation         |
  | --------- | -------------------------- |
  | `{"a":1}` | `0C0000001061000100000000` |
  | `{"b":2}` | `0C0000001062000200000000` |
  | `{"c":3}` | `0C0000001063000300000000` |
  | `{"d":4}` | `0C0000001064000400000000` |

***

Modified at: July 10, 2025

Source: [/db/v9.1/reference/sql-reference/bson-functions/bson-input-stream-to-array/](https://docs.singlestore.com/db/v9.1/reference/sql-reference/bson-functions/bson-input-stream-to-array/)

(An index of the documentation is available at /llms.txt)
