title_wip

[Edit this page](https://github.com/ClickHouse/ClickHouse/tree/master/docs/en/interfaces/formats/BSONEachRow.md)

|  |  |  |  |  |  |
| --- | --- | --- | --- | --- | --- |
| Input Output Alias|  |  |  | | --- | --- | --- | | ✔ ✔  | | | | | |

## Description[​](#description "Direct link to Description")

The `BSONEachRow` format parses data as a sequence of Binary JSON (BSON) documents without any separator between them.
Each row is formatted as a single document and each column is formatted as a single BSON document field with the column name as a key.

## Data types matching[​](#data-types-matching "Direct link to Data types matching")

For output it uses the following correspondence between ClickHouse types and BSON types:

|  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| ClickHouse type BSON Type|  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | [Bool](/docs/sql-reference/data-types/boolean) `\x08` boolean| [Int8/UInt8](/docs/sql-reference/data-types/int-uint)/[Enum8](/docs/sql-reference/data-types/enum) `\x10` int32| [Int16/UInt16](/docs/sql-reference/data-types/int-uint)/[Enum16](/docs/sql-reference/data-types/enum) `\x10` int32| [Int32](/docs/sql-reference/data-types/int-uint) `\x10` int32| [UInt32](/docs/sql-reference/data-types/int-uint) `\x12` int64| [Int64/UInt64](/docs/sql-reference/data-types/int-uint) `\x12` int64| [Float32/Float64](/docs/sql-reference/data-types/float) `\x01` double| [Date](/docs/sql-reference/data-types/date)/[Date32](/docs/sql-reference/data-types/date32) `\x10` int32| [DateTime](/docs/sql-reference/data-types/datetime) `\x12` int64| [DateTime64](/docs/sql-reference/data-types/datetime64) `\x09` datetime| [Decimal32](/docs/sql-reference/data-types/decimal) `\x10` int32| [Decimal64](/docs/sql-reference/data-types/decimal) `\x12` int64| [Decimal128](/docs/sql-reference/data-types/decimal) `\x05` binary, `\x00` binary subtype, size = 16| [Decimal256](/docs/sql-reference/data-types/decimal) `\x05` binary, `\x00` binary subtype, size = 32| [Int128/UInt128](/docs/sql-reference/data-types/int-uint) `\x05` binary, `\x00` binary subtype, size = 16| [Int256/UInt256](/docs/sql-reference/data-types/int-uint) `\x05` binary, `\x00` binary subtype, size = 32| [String](/docs/sql-reference/data-types/string)/[FixedString](/docs/sql-reference/data-types/fixedstring) `\x05` binary, `\x00` binary subtype or \x02 string if setting output\_format\_bson\_string\_as\_string is enabled| [UUID](/docs/sql-reference/data-types/uuid) `\x05` binary, `\x04` uuid subtype, size = 16| [Array](/docs/sql-reference/data-types/array) `\x04` array| [Tuple](/docs/sql-reference/data-types/tuple) `\x04` array| [Named Tuple](/docs/sql-reference/data-types/tuple) `\x03` document| [Map](/docs/sql-reference/data-types/map) `\x03` document| [IPv4](/docs/sql-reference/data-types/ipv4) `\x10` int32| [IPv6](/docs/sql-reference/data-types/ipv6) `\x05` binary, `\x00` binary subtype | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |

For input it uses the following correspondence between BSON types and ClickHouse types:

|  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| BSON Type ClickHouse Type|  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | `\x01` double [Float32/Float64](/docs/sql-reference/data-types/float)| `\x02` string [String](/docs/sql-reference/data-types/string)/[FixedString](/docs/sql-reference/data-types/fixedstring)| `\x03` document [Map](/docs/sql-reference/data-types/map)/[Named Tuple](/docs/sql-reference/data-types/tuple)| `\x04` array [Array](/docs/sql-reference/data-types/array)/[Tuple](/docs/sql-reference/data-types/tuple)| `\x05` binary, `\x00` binary subtype [String](/docs/sql-reference/data-types/string)/[FixedString](/docs/sql-reference/data-types/fixedstring)/[IPv6](/docs/sql-reference/data-types/ipv6)| `\x05` binary, `\x02` old binary subtype [String](/docs/sql-reference/data-types/string)/[FixedString](/docs/sql-reference/data-types/fixedstring)| `\x05` binary, `\x03` old uuid subtype [UUID](/docs/sql-reference/data-types/uuid)| `\x05` binary, `\x04` uuid subtype [UUID](/docs/sql-reference/data-types/uuid)| `\x07` ObjectId [String](/docs/sql-reference/data-types/string)/[FixedString](/docs/sql-reference/data-types/fixedstring)| `\x08` boolean [Bool](/docs/sql-reference/data-types/boolean)| `\x09` datetime [DateTime64](/docs/sql-reference/data-types/datetime64)| `\x0A` null value [NULL](/docs/sql-reference/data-types/nullable)| `\x0D` JavaScript code [String](/docs/sql-reference/data-types/string)/[FixedString](/docs/sql-reference/data-types/fixedstring)| `\x0E` symbol [String](/docs/sql-reference/data-types/string)/[FixedString](/docs/sql-reference/data-types/fixedstring)| `\x10` int32 [Int32/UInt32](/docs/sql-reference/data-types/int-uint)/[Decimal32](/docs/sql-reference/data-types/decimal)/[IPv4](/docs/sql-reference/data-types/ipv4)/[Enum8/Enum16](/docs/sql-reference/data-types/enum)| `\x12` int64 [Int64/UInt64](/docs/sql-reference/data-types/int-uint)/[Decimal64](/docs/sql-reference/data-types/decimal)/[DateTime64](/docs/sql-reference/data-types/datetime64) | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |

Other BSON types are not supported. Additionally, it performs conversion between different integer types.
For example, it is possible to insert a BSON `int32` value into ClickHouse as [`UInt8`](/docs/sql-reference/data-types/int-uint).

Big integers and decimals such as `Int128`/`UInt128`/`Int256`/`UInt256`/`Decimal128`/`Decimal256` can be parsed from a BSON Binary value with the `\x00` binary subtype.
In this case, the format will validate that the size of the binary data equals the size of the expected value.

Note

This format does not work properly on Big-Endian platforms.

## Example usage[​](#example-usage "Direct link to Example usage")

### Inserting data[​](#inserting-data "Direct link to Inserting data")

Using a BSON file with the following data, named as `football.bson`: