> ## Documentation Index
> Fetch the complete documentation index at: https://clickhouse.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

> ClickHouse 中支持的输入和输出数据格式概览

# 输入和输出数据格式

export const CloudNotSupportedBadge = () => {
  return <div className="cloudNotSupportedBadge">
            <div className="cloudNotSupportedIcon">
            <svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
                <path strokeWidth="1.5" d="M6.33366 12.6666L12.3739 12.6667C13.6593 12.6667 14.7073 11.6187 14.7073 10.3334C14.7073 9.04804 13.6593 8.00003 12.3739 8.00003C12.3739 8.00003 12.3337 7.66659 12.0003 7.33325M10.667 5.33322C8.00033 2.33325 4.45395 4.78537 4.14195 6.68203C2.55728 6.7627 1.29395 8.06203 1.29395 9.6667C1.29395 11.3234 2.66699 12.6666 4.00033 12.6666" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" />
                <path strokeWidth="1.5" d="M2.66699 14L12.0003 4.66663" stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" />
            </svg>

        </div>
            ClickHouse Cloud 不支持此功能
        </div>;
};

ClickHouse 支持大多数已知的文本和二进制数据格式。这使其能够轻松集成到几乎任何现有的数据管道中，
从而充分发挥 ClickHouse 的优势。

<div id="input-formats">
  ## 输入格式
</div>

输入格式用于：

* 解析提供给 `INSERT` 语句的数据
* 从 `File`、`URL` 或 `HDFS` 等以文件为后端的表执行 `SELECT` 查询
* 读取字典

选择合适的输入格式，对于在 ClickHouse 中高效摄取数据至关重要。支持的格式超过 70 种，
选择性能最佳的格式会显著影响插入速度、CPU 和内存占用，以及整体系统
效率。为了帮助你更好地在这些选项之间做出选择，我们对不同格式的摄取性能进行了基准测试，并总结出以下关键结论：

* **[Native](/docs/zh/reference/formats/Native) 格式是效率最高的输入格式**，具备最佳压缩效果、最低
  资源占用，以及最小的服务端处理开销。
* **压缩至关重要** - LZ4 能以极低的 CPU 代价减小数据体积，而 ZSTD 则能提供更高的压缩率，但
  会增加 CPU 使用。
* **预排序的影响较为有限**，因为 ClickHouse 本身已经能够高效完成排序。
* **批处理可显著提升效率** - 更大的批次可减少插入开销并提高吞吐量。

如需深入了解测试结果和最佳实践，
请阅读完整的[基准分析](https://www.clickhouse.com/blog/clickhouse-input-format-matchup-which-is-fastest-most-efficient)。
如需查看完整测试结果，请访问 [FastFormats](https://fastformats.clickhouse.com/) 在线仪表板。

<div id="output-formats">
  ## 输出格式
</div>

支持输出的格式可用于：

* 格式化 `SELECT` 查询结果
* 对以文件为后端的表执行 `INSERT` 操作

<div id="formats-overview">
  ## 格式概述
</div>

支持的格式如下：

| 格式                                                                                                                                 | 输入 | 输出 |
| ---------------------------------------------------------------------------------------------------------------------------------- | -- | -- |
| [TabSeparated](/docs/zh/reference/formats/TabSeparated/TabSeparated)                                                                    | ✔  | ✔  |
| [TabSeparatedRaw](/docs/zh/reference/formats/TabSeparated/TabSeparatedRaw)                                                              | ✔  | ✔  |
| [TabSeparatedWithNames](/docs/zh/reference/formats/TabSeparated/TabSeparatedWithNames)                                                  | ✔  | ✔  |
| [TabSeparatedWithNamesAndTypes](/docs/zh/reference/formats/TabSeparated/TabSeparatedWithNamesAndTypes)                                  | ✔  | ✔  |
| [TabSeparatedRawWithNames](/docs/zh/reference/formats/TabSeparated/TabSeparatedRawWithNames)                                            | ✔  | ✔  |
| [TabSeparatedRawWithNamesAndTypes](/docs/zh/reference/formats/TabSeparated/TabSeparatedRawWithNamesAndTypes)                            | ✔  | ✔  |
| [Template](/docs/zh/reference/formats/Template/Template)                                                                                | ✔  | ✔  |
| [TemplateIgnoreSpaces](/docs/zh/reference/formats/Template/TemplateIgnoreSpaces)                                                        | ✔  | ✗  |
| [CSV](/docs/zh/reference/formats/CSV/CSV)                                                                                               | ✔  | ✔  |
| [CSVWithNames](/docs/zh/reference/formats/CSV/CSVWithNames)                                                                             | ✔  | ✔  |
| [CSVWithNamesAndTypes](/docs/zh/reference/formats/CSV/CSVWithNamesAndTypes)                                                             | ✔  | ✔  |
| [CustomSeparated](/docs/zh/reference/formats/CustomSeparated/CustomSeparated)                                                           | ✔  | ✔  |
| [CustomSeparatedIgnoreSpaces](/docs/zh/reference/formats/CustomSeparated/CustomSeparatedIgnoreSpaces)                                   | ✔  | ✗  |
| [CustomSeparatedIgnoreSpacesWithNames](/docs/zh/reference/formats/CustomSeparated/CustomSeparatedIgnoreSpacesWithNames)                 | ✔  | ✗  |
| [CustomSeparatedIgnoreSpacesWithNamesAndTypes](/docs/zh/reference/formats/CustomSeparated/CustomSeparatedIgnoreSpacesWithNamesAndTypes) | ✔  | ✗  |
| [CustomSeparatedWithNames](/docs/zh/reference/formats/CustomSeparated/CustomSeparatedWithNames)                                         | ✔  | ✔  |
| [CustomSeparatedWithNamesAndTypes](/docs/zh/reference/formats/CustomSeparated/CustomSeparatedWithNamesAndTypes)                         | ✔  | ✔  |
| [HiveText](/docs/zh/reference/formats/HiveText)                                                                                         | ✔  | ✗  |
| [SQLInsert](/docs/zh/reference/formats/SQLInsert)                                                                                       | ✗  | ✔  |
| [Values](/docs/zh/reference/formats/Values)                                                                                             | ✔  | ✔  |
| [Vertical](/docs/zh/reference/formats/Vertical)                                                                                         | ✗  | ✔  |
| [JSON](/docs/zh/reference/formats/JSON/JSON)                                                                                            | ✔  | ✔  |
| [JSONAsString](/docs/zh/reference/formats/JSON/JSONAsString)                                                                            | ✔  | ✗  |
| [JSONAsObject](/docs/zh/reference/formats/JSON/JSONAsObject)                                                                            | ✔  | ✗  |
| [JSONStrings](/docs/zh/reference/formats/JSON/JSONStrings)                                                                              | ✗  | ✔  |
| [JSONColumns](/docs/zh/reference/formats/JSON/JSONColumns)                                                                              | ✔  | ✔  |
| [JSONColumnsWithMetadata](/docs/zh/reference/formats/JSON/JSONColumnsWithMetadata)                                                      | ✔  | ✔  |
| [JSONCompact](/docs/zh/reference/formats/JSON/JSONCompact)                                                                              | ✔  | ✔  |
| [JSONCompactStrings](/docs/zh/reference/formats/JSON/JSONCompactStrings)                                                                | ✗  | ✔  |
| [JSONCompactColumns](/docs/zh/reference/formats/JSON/JSONCompactColumns)                                                                | ✔  | ✔  |
| [JSONEachRow](/docs/zh/reference/formats/JSON/JSONEachRow)                                                                              | ✔  | ✔  |
| [JSONLines](/docs/zh/reference/formats/JSON/JSONLines)                                                                                  | ✔  | ✔  |
| [PrettyJSONEachRow](/docs/zh/reference/formats/JSON/PrettyJSONEachRow)                                                                  | ✗  | ✔  |
| [JSONEachRowWithProgress](/docs/zh/reference/formats/JSON/JSONEachRowWithProgress)                                                      | ✗  | ✔  |
| [JSONStringsEachRow](/docs/zh/reference/formats/JSON/JSONStringsEachRow)                                                                | ✔  | ✔  |
| [JSONStringsEachRowWithProgress](/docs/zh/reference/formats/JSON/JSONStringsEachRowWithProgress)                                        | ✗  | ✔  |
| [JSONCompactEachRow](/docs/zh/reference/formats/JSON/JSONCompactEachRow)                                                                | ✔  | ✔  |
| [JSONCompactEachRowWithNames](/docs/zh/reference/formats/JSON/JSONCompactEachRowWithNames)                                              | ✔  | ✔  |
| [JSONCompactEachRowWithNamesAndTypes](/docs/zh/reference/formats/JSON/JSONCompactEachRowWithNamesAndTypes)                              | ✔  | ✔  |
| [JSONCompactEachRowWithProgress](/docs/zh/reference/formats/JSON/JSONCompactEachRowWithProgress)                                        | ✗  | ✔  |
| [JSONCompactStringsEachRow](/docs/zh/reference/formats/JSON/JSONCompactStringsEachRow)                                                  | ✔  | ✔  |
| [JSONCompactStringsEachRowWithNames](/docs/zh/reference/formats/JSON/JSONCompactStringsEachRowWithNames)                                | ✔  | ✔  |
| [JSONCompactStringsEachRowWithNamesAndTypes](/docs/zh/reference/formats/JSON/JSONCompactStringsEachRowWithNamesAndTypes)                | ✔  | ✔  |
| [JSONCompactStringsEachRowWithProgress](/docs/zh/reference/formats/JSON/JSONCompactStringsEachRowWithProgress)                          | ✗  | ✔  |
| [JSONObjectEachRow](/docs/zh/reference/formats/JSON/JSONObjectEachRow)                                                                  | ✔  | ✔  |
| [BSONEachRow](/docs/zh/reference/formats/BSONEachRow)                                                                                   | ✔  | ✔  |
| [TSKV](/docs/zh/reference/formats/TabSeparated/TSKV)                                                                                    | ✔  | ✔  |
| [Pretty](/docs/zh/reference/formats/Pretty/Pretty)                                                                                      | ✗  | ✔  |
| [PrettyNoEscapes](/docs/zh/reference/formats/Pretty/PrettyNoEscapes)                                                                    | ✗  | ✔  |
| [PrettyMonoBlock](/docs/zh/reference/formats/Pretty/PrettyMonoBlock)                                                                    | ✗  | ✔  |
| [PrettyNoEscapesMonoBlock](/docs/zh/reference/formats/Pretty/PrettyNoEscapesMonoBlock)                                                  | ✗  | ✔  |
| [PrettyCompact](/docs/zh/reference/formats/Pretty/PrettyCompact)                                                                        | ✗  | ✔  |
| [PrettyCompactNoEscapes](/docs/zh/reference/formats/Pretty/PrettyCompactNoEscapes)                                                      | ✗  | ✔  |
| [PrettyCompactMonoBlock](/docs/zh/reference/formats/Pretty/PrettyCompactMonoBlock)                                                      | ✗  | ✔  |
| [PrettyCompactNoEscapesMonoBlock](/docs/zh/reference/formats/Pretty/PrettyCompactNoEscapesMonoBlock)                                    | ✗  | ✔  |
| [PrettySpace](/docs/zh/reference/formats/Pretty/PrettySpace)                                                                            | ✗  | ✔  |
| [PrettySpaceNoEscapes](/docs/zh/reference/formats/Pretty/PrettySpaceNoEscapes)                                                          | ✗  | ✔  |
| [PrettySpaceMonoBlock](/docs/zh/reference/formats/Pretty/PrettySpaceMonoBlock)                                                          | ✗  | ✔  |
| [PrettySpaceNoEscapesMonoBlock](/docs/zh/reference/formats/Pretty/PrettySpaceNoEscapesMonoBlock)                                        | ✗  | ✔  |
| [Prometheus](/docs/zh/reference/formats/Prometheus)                                                                                     | ✗  | ✔  |
| [Protobuf](/docs/zh/reference/formats/Protobuf/Protobuf)                                                                                | ✔  | ✔  |
| [ProtobufSingle](/docs/zh/reference/formats/Protobuf/ProtobufSingle)                                                                    | ✔  | ✔  |
| [ProtobufList](/docs/zh/reference/formats/Protobuf/ProtobufList)                                                                        | ✔  | ✔  |
| [Avro](/docs/zh/reference/formats/Avro/Avro)                                                                                            | ✔  | ✔  |
| [AvroConfluent](/docs/zh/reference/formats/Avro/AvroConfluent)                                                                          | ✔  | ✔  |
| [Parquet](/docs/zh/reference/formats/Parquet/Parquet)                                                                                   | ✔  | ✔  |
| [ParquetMetadata](/docs/zh/reference/formats/Parquet/ParquetMetadata)                                                                   | ✔  | ✗  |
| [Arrow](/docs/zh/reference/formats/Arrow/Arrow)                                                                                         | ✔  | ✔  |
| [ArrowStream](/docs/zh/reference/formats/Arrow/ArrowStream)                                                                             | ✔  | ✔  |
| [ORC](/docs/zh/reference/formats/ORC)                                                                                                   | ✔  | ✔  |
| [One](/docs/zh/reference/formats/One)                                                                                                   | ✔  | ✗  |
| [Npy](/docs/zh/reference/formats/Npy)                                                                                                   | ✔  | ✔  |
| [RowBinary](/docs/zh/reference/formats/RowBinary/RowBinary)                                                                             | ✔  | ✔  |
| [RowBinaryWithNames](/docs/zh/reference/formats/RowBinary/RowBinaryWithNames)                                                           | ✔  | ✔  |
| [RowBinaryWithNamesAndTypes](/docs/zh/reference/formats/RowBinary/RowBinaryWithNamesAndTypes)                                           | ✔  | ✔  |
| [RowBinaryWithDefaults](/docs/zh/reference/formats/RowBinary/RowBinaryWithDefaults)                                                     | ✔  | ✗  |
| [RowBinaryWithNamesAndTypesAndDefaults](/docs/zh/reference/formats/RowBinary/RowBinaryWithNamesAndTypesAndDefaults)                     | ✔  | ✗  |
| [Native](/docs/zh/reference/formats/Native)                                                                                             | ✔  | ✔  |
| [Buffers](/docs/zh/reference/formats/Buffers)                                                                                           | ✔  | ✔  |
| [Null](/docs/zh/reference/formats/Null)                                                                                                 | ✗  | ✔  |
| [Hash](/docs/zh/reference/formats/Hash)                                                                                                 | ✗  | ✔  |
| [XML](/docs/zh/reference/formats/XML)                                                                                                   | ✗  | ✔  |
| [CapnProto](/docs/zh/reference/formats/CapnProto)                                                                                       | ✔  | ✔  |
| [LineAsString](/docs/zh/reference/formats/LineAsString/LineAsString)                                                                    | ✔  | ✔  |
| [LineAsStringWithNames](/docs/zh/reference/formats/LineAsString/LineAsStringWithNames)                                                  | ✗  | ✔  |
| [LineAsStringWithNamesAndTypes](/docs/zh/reference/formats/LineAsString/LineAsStringWithNamesAndTypes)                                  | ✗  | ✔  |
| [Regexp](/docs/zh/reference/formats/Regexp)                                                                                             | ✔  | ✗  |
| [RawBLOB](/docs/zh/reference/formats/RawBLOB)                                                                                           | ✔  | ✔  |
| [MsgPack](/docs/zh/reference/formats/MsgPack)                                                                                           | ✔  | ✔  |
| [MySQLDump](/docs/zh/reference/formats/MySQLDump)                                                                                       | ✔  | ✗  |
| [MySQLWire](/docs/zh/reference/formats/MySQLWire)                                                                                       | ✗  | ✔  |
| [PostgreSQLWire](/docs/zh/reference/formats/PostgreSQLWire)                                                                             | ✗  | ✔  |
| [ODBCDriver2](/docs/zh/reference/formats/ODBCDriver2)                                                                                   | ✗  | ✔  |
| [GeoJSON](/docs/zh/reference/formats/GeoJSON)                                                                                           | ✔  | ✔  |
| [DWARF](/docs/zh/reference/formats/DWARF)                                                                                               | ✔  | ✗  |
| [Markdown](/docs/zh/reference/formats/Markdown)                                                                                         | ✗  | ✔  |
| [Form](/docs/zh/reference/formats/Form)                                                                                                 | ✔  | ✗  |

您可以通过 ClickHouse 设置控制某些格式处理参数。更多信息，请参阅 [设置](/docs/zh/reference/settings/formats) 部分。

JSON 特有的其他设置记录在 [JSON 格式设置](/docs/zh/reference/formats/JSON/format-settings) 页面中。

<div id="formatschema">
  ## 格式 schema
</div>

包含格式 schema 的文件名由设置 `format_schema` 指定。
使用 `Cap'n Proto` 和 `Protobuf` 这两种格式之一时，必须设置此项。
格式 schema 由文件名和该文件中的消息类型名称组成，二者以冒号分隔，
例如 `schemafile.proto:MessageType`。
如果文件使用该格式的标准扩展名 (例如 `Protobuf` 的 `.proto`) ，
则可以省略扩展名，此时格式 schema 形如 `schemafile:MessageType`。

如果你通过处于交互模式的[客户端](/docs/zh/concepts/features/interfaces/client)输入或输出数据，则格式 schema 中指定的文件名
可以包含绝对路径，或相对于客户端当前目录的路径。
如果你在[批次模式](/docs/zh/concepts/features/interfaces/client#batch-mode)下使用客户端，出于安全原因，schema 的路径必须是相对路径。

如果你通过 [HTTP 接口](/docs/zh/concepts/features/interfaces/http) 输入或输出数据，则格式 schema 中指定的文件名
应位于服务器配置中 [format\_schema\_path](/docs/zh/reference/settings/server-settings/settings#format_schema_path)
指定的目录下。

<div id="skippingerrors">
  ## 跳过错误
</div>

某些格式 (如 `CSV`、`TabSeparated`、`TSKV`、`JSONEachRow`、`Template`、`CustomSeparated` 和 `Protobuf`) 在发生解析错误时，可以跳过损坏的行，并从下一行的开头继续解析。请参阅设置 [input\_format\_allow\_errors\_num](/docs/zh/reference/settings/formats#input_format_allow_errors_num) 和
[input\_format\_allow\_errors\_ratio](/docs/zh/reference/settings/formats#input_format_allow_errors_ratio)。
限制：

* 发生解析错误时，`JSONEachRow` 会跳过直到换行符 (或 EOF) 之前的所有数据，因此各行必须以 `\n` 分隔，才能正确统计错误数。
* `Template` 和 `CustomSeparated` 通过最后一列后的分隔符以及行间分隔符来定位下一行的开头，因此只有当其中至少一个非空时，才支持跳过错误。
