Exporting in a Native ClickHouse format
The most efficient data format to export and import data between ClickHouse nodes is Native format. Exporting is done usingINTO OUTFILE clause:
Importing from a Native format
To import data, we can use file() for smaller files or exploration purposes:FROM INFILE to import data:
Native format compression
We can also enable compression while exporting data to Native format (as well as most other formats) using aCOMPRESSION clause:
Exporting to RowBinary
Another binary format supported is RowBinary, which allows importing and exporting data in binary-represented rows:Exploring RowBinary files
Automatic schema inference isn’t supported for this format, so to explore before loading, we have to define schema explicitly:Importing from RowBinary files
To load data from a RowBinary file, we can use aFROM INFILE clause:
Importing single binary value using RawBLOB
Suppose we want to read an entire binary file and save it into a field in a table. This is the case when the RawBLOB format can be used. This format can be directly used with a single-column table only:images table:
data field length which will be equal to the original file size:
Exporting RawBLOB data
This format can also be used to export data using anINTO OUTFILE clause:
LIMIT 1 because exporting more than a single value will create a corrupted file.
MessagePack
ClickHouse supports importing and exporting to MessagePack using the MsgPack. To export to MessagePack format:Protocol Buffers
To work with Protocol Buffers we first need to define a schema file:schema.proto in our case) is set in a format_schema settings option for the Protobuf format:
Cap’n Proto
Another popular binary serialization format supported by ClickHouse is Cap’n Proto. Similarly toProtobuf format, we have to define a schema file (schema.capnp) in our example:
Date column as UInt32 to match corresponding types.
Other formats
ClickHouse introduces support for many formats, both text, and binary, to cover various scenarios and platforms. Explore more formats and ways to work with them in the following articles:- CSV and TSV formats
- Parquet
- JSON formats
- Regex and templates
- Native and binary formats
- SQL formats