# BSON\_ARRAY\_PUSH

Adds the specified BSON value to the end of the input BSON array, and returns the array with the appended value as the result.

## Syntax

```
BSON_ARRAY_PUSH(<array>, <value>)
```

## Arguments

* `<array>`: A valid BSON array or an expression that evaluates to a BSON array.
* `<value>`: A BSON value to be appended to the input array.

## Return Type

A BSON array.

## Remarks

* If `NULL` is specified as the input array, it is considered as an empty BSON array.
* If `NULL` is specified as the value to append, it is considered as the BSON `NULL` type.

## Examples

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

```sql
SELECT BSON_ARRAY_PUSH('[1, true, null, [7,8,9], "abc"]':>BSON, '{"a":{"b":9}}':>BSON):>JSON AS Result;

```

```output

+-------------------------------------------+
| Result                                    |
+-------------------------------------------+
| [1,true,null,[7,8,9],"abc",{"a":{"b":9}}] |
+-------------------------------------------+

```

```sql
SELECT BSON_ARRAY_PUSH('[]':>BSON, '"abc"':>BSON):>JSON AS Result;

```

```output

+---------+
| Result  |
+---------+
| ["abc"] |
+---------+
```

```sql
SELECT BSON_ARRAY_PUSH('[1,2,3,4]':>BSON, 'null':>BSON):>JSON AS Result;

```

```output

+----------------+
| Result         |
+----------------+
| [1,2,3,4,null] |
+----------------+
```

***

Modified at: April 2, 2024

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

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