> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-mintlify-8c05c8a2.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> Values 格式文档

# Values

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

<div id="description">
  ## 描述
</div>

`Values` 格式会将每行输出为方括号括起来的形式。

* 各行之间以逗号分隔，最后一行后不加逗号。
* 方括号内的值也以逗号分隔。
* 数字以十进制格式输出，不带引号。
* 数组输出为 `[]`。
* 字符串、日期和日期时间会带引号输出。
* 转义规则和解析方式与 [TabSeparated](/zh/reference/formats/TabSeparated/TabSeparated) 格式类似。

格式化时不会插入额外空格；但解析时允许空格并会将其跳过 (数组值内部的空格除外，此处不允许空格) 。
[`NULL`](/zh/reference/syntax) 表示为 `NULL`。

以 `Values` 格式传递数据时，至少需要转义以下字符：

* 单引号
* 反斜杠

这是 `INSERT INTO t VALUES ...` 中使用的格式，但也可以用来格式化查询结果。

<div id="example-usage">
  ## 示例用法
</div>

<div id="inserting-data">
  ### 插入数据
</div>

`Values` 格式就是 `INSERT` 使用的格式，因此任何 `INSERT ... VALUES` 语句
实际上都已经在使用这种格式。也可以显式指定 `FORMAT Values` 子句，并且
这些行可以通过 stream 或文件提供。每一行都是一个用括号括起来、以逗号分隔的元组，
而元组之间也同样用逗号分隔：

```sql title="Query" theme={null}
CREATE TABLE t (id UInt32, name String, values Array(UInt32)) ENGINE = Memory;

INSERT INTO t FORMAT Values (1, 'a', [10, 20]), (2, 'b', [30]);

SELECT * FROM t ORDER BY id;
```

```response title="Response" theme={null}
┌─id─┬─name─┬─values──┐
│  1 │ a    │ [10,20] │
│  2 │ b    │ [30]    │
└────┴──────┴─────────┘
```

<div id="using-expressions">
  ### 在输入中使用表达式
</div>

与大多数输入格式不同，`Values` 可以对每个字段中的 SQL 表达式求值，
而不只是接受字面量。这由
[`input_format_values_interpret_expressions`](#format-settings) 控制 (默认
启用) ：当某个字段无法由快速流式解析器解析时，ClickHouse
会回退到 SQL 解析器，并将该字段作为表达式来解释。

```sql title="Query" theme={null}
CREATE TABLE prices (item String, total UInt32) ENGINE = Memory;

INSERT INTO prices FORMAT Values ('apple', 3 * 4), ('pear', length('hello') + 10);

SELECT * FROM prices ORDER BY total;
```

```response title="Response" theme={null}
┌─item──┬─total─┐
│ apple │    12 │
│ pear  │    15 │
└───────┴───────┘
```

<div id="selecting-data">
  ### 查询数据
</div>

`Values` 格式也可用于格式化查询结果。数字
不加引号，数组写在 `[]` 中，字符串和日期用单引号括起；
字符串中的单引号和反斜杠需要用反斜杠转义，而
[`NULL`](/zh/reference/syntax) 则写作 `NULL`：

```sql title="Query" theme={null}
SELECT 1 AS a, 'O''Reilly' AS b, NULL::Nullable(String) AS c FORMAT Values;
```

```response title="Response" theme={null}
(1,'O\'Reilly',NULL)
```

<div id="format-settings">
  ## 格式设置
</div>

| 设置                                                                                                                                          | 描述                                                                        | 默认值    |
| ------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------- | ------ |
| [`input_format_values_interpret_expressions`](/zh/reference/settings/formats#input_format_values_interpret_expressions)                     | 如果字段无法由流式解析器解析，则运行 SQL 解析器并尝试将其解释为 SQL 表达式。                               | `true` |
| [`input_format_values_deduce_templates_of_expressions`](/zh/reference/settings/formats#input_format_values_deduce_templates_of_expressions) | 如果字段无法由流式解析器解析，则运行 SQL 解析器，推导出 SQL 表达式的模板，尝试使用该模板解析所有行，然后将其作为表达式解释应用到所有行。 | `true` |
| [`input_format_values_accurate_types_of_literals`](/zh/reference/settings/formats#input_format_values_accurate_types_of_literals)           | 在使用模板解析和解释表达式时，检查字面量的实际类型，以避免可能出现的溢出和精度问题。                                | `true` |
