> ## 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.

# CustomSeparated

> CustomSeparated 格式说明

| 输入 | 输出 | 别名 |
| - | - | - |
| ✔ | ✔ | |

## 描述

与 [Template](https://clickhouse.com/docs/zh/reference/formats/Template/Template.md) 类似，但它会输出或读取所有列的名称和类型，并使用 [format\_custom\_escaping\_rule](https://clickhouse.com/docs/zh/reference/settings/formats/format-custom.md#format_custom_escaping_rule) 设置中的转义规则，以及以下设置中的分隔符：

* [format\_custom\_field\_delimiter](https://clickhouse.com/docs/zh/reference/settings/formats/format-custom.md#format_custom_field_delimiter)
* [format\_custom\_row\_before\_delimiter](https://clickhouse.com/docs/zh/reference/settings/formats/format-custom.md#format_custom_row_before_delimiter)
* [format\_custom\_row\_after\_delimiter](https://clickhouse.com/docs/zh/reference/settings/formats/format-custom.md#format_custom_row_after_delimiter)
* [format\_custom\_row\_between\_delimiter](https://clickhouse.com/docs/zh/reference/settings/formats/format-custom.md#format_custom_row_between_delimiter)
* [format\_custom\_result\_before\_delimiter](https://clickhouse.com/docs/zh/reference/settings/formats/format-custom.md#format_custom_result_before_delimiter)
* [format\_custom\_result\_after\_delimiter](https://clickhouse.com/docs/zh/reference/settings/formats/format-custom.md#format_custom_result_after_delimiter)

> [!NOTE]
>
> 它不使用格式字符串中的转义规则设置和分隔符。

此外，还有 [`CustomSeparatedIgnoreSpaces`](https://clickhouse.com/docs/zh/reference/formats/CustomSeparated/CustomSeparatedIgnoreSpaces) 格式，它与 [TemplateIgnoreSpaces](https://clickhouse.com/docs/zh/reference/formats/Template/TemplateIgnoreSpaces.md) 类似。

## 使用示例

### 插入数据

使用下面这个名为 `football.txt` 的 txt 文件：

```text theme={null}
row('2022-04-30';2021;'Sutton United';'Bradford City';1;4),row('2022-04-30';2021;'Swindon Town';'Barrow';2;1),row('2022-04-30';2021;'Tranmere Rovers';'Oldham Athletic';2;0),row('2022-05-02';2021;'Salford City';'Mansfield Town';2;2),row('2022-05-02';2021;'Port Vale';'Newport County';1;2),row('2022-05-07';2021;'Barrow';'Northampton Town';1;3),row('2022-05-07';2021;'Bradford City';'Carlisle United';2;0),row('2022-05-07';2021;'Bristol Rovers';'Scunthorpe United';7;0),row('2022-05-07';2021;'Exeter City';'Port Vale';0;1),row('2022-05-07';2021;'Harrogate Town A.F.C.';'Sutton United';0;2),row('2022-05-07';2021;'Hartlepool United';'Colchester United';0;2),row('2022-05-07';2021;'Leyton Orient';'Tranmere Rovers';0;1),row('2022-05-07';2021;'Mansfield Town';'Forest Green Rovers';2;2),row('2022-05-07';2021;'Newport County';'Rochdale';0;2),row('2022-05-07';2021;'Oldham Athletic';'Crawley Town';3;3),row('2022-05-07';2021;'Stevenage Borough';'Salford City';4;2),row('2022-05-07';2021;'Walsall';'Swindon Town';0;3)
```

配置自定义分隔符的相关设置：

```sql theme={null}
SET format_custom_row_before_delimiter = 'row(';
SET format_custom_row_after_delimiter = ')';
SET format_custom_field_delimiter = ';';
SET format_custom_row_between_delimiter = ',';
SET format_custom_escaping_rule = 'Quoted';
```

插入数据：

```sql theme={null}
INSERT INTO football FROM INFILE 'football.txt' FORMAT CustomSeparated;
```

### 读取数据

配置自定义分隔符相关设置：

```sql theme={null}
SET format_custom_row_before_delimiter = 'row(';
SET format_custom_row_after_delimiter = ')';
SET format_custom_field_delimiter = ';';
SET format_custom_row_between_delimiter = ',';
SET format_custom_escaping_rule = 'Quoted';
```

使用 `CustomSeparated` 格式读取数据：

```sql theme={null}
SELECT *
FROM football
FORMAT CustomSeparated
```

输出将以已配置的自定义格式显示：

```text theme={null}
row('2022-04-30';2021;'Sutton United';'Bradford City';1;4),row('2022-04-30';2021;'Swindon Town';'Barrow';2;1),row('2022-04-30';2021;'Tranmere Rovers';'Oldham Athletic';2;0),row('2022-05-02';2021;'Port Vale';'Newport County';1;2),row('2022-05-02';2021;'Salford City';'Mansfield Town';2;2),row('2022-05-07';2021;'Barrow';'Northampton Town';1;3),row('2022-05-07';2021;'Bradford City';'Carlisle United';2;0),row('2022-05-07';2021;'Bristol Rovers';'Scunthorpe United';7;0),row('2022-05-07';2021;'Exeter City';'Port Vale';0;1),row('2022-05-07';2021;'Harrogate Town A.F.C.';'Sutton United';0;2),row('2022-05-07';2021;'Hartlepool United';'Colchester United';0;2),row('2022-05-07';2021;'Leyton Orient';'Tranmere Rovers';0;1),row('2022-05-07';2021;'Mansfield Town';'Forest Green Rovers';2;2),row('2022-05-07';2021;'Newport County';'Rochdale';0;2),row('2022-05-07';2021;'Oldham Athletic';'Crawley Town';3;3),row('2022-05-07';2021;'Stevenage Borough';'Salford City';4;2),row('2022-05-07';2021;'Walsall';'Swindon Town';0;3)
```

## 格式设置

其他设置：

| 设置 | 描述 | 默认值 |
| - | - | - |
| [input\_format\_custom\_detect\_header](https://clickhouse.com/docs/zh/reference/settings/formats/input-format.md#input_format_custom_detect_header) | 如果存在包含名称和类型的标头，则启用自动检测。 | `true` |
| [input\_format\_custom\_skip\_trailing\_empty\_lines](https://clickhouse.com/docs/zh/reference/settings/formats/input-format.md#input_format_custom_skip_trailing_empty_lines) | 跳过文件末尾的空行。 | `false` |
| [input\_format\_custom\_allow\_variable\_number\_of\_columns](https://clickhouse.com/docs/zh/reference/settings/formats/input-format.md#input_format_custom_allow_variable_number_of_columns) | 在 CustomSeparated 格式中允许列数可变，忽略多余的列，并为缺失的列使用默认值。 | `false` |
