Help wanted!

The following content of this documentation page has been machine-translated. But unlike other websites, it is not done on the fly. This translated text lives on GitHub repository alongside main ClickHouse codebase and waits for fellow native speakers to make it more human-readable. You can also use the original English version as a reference.

Help ClickHouse documentation by editing this page

输入

input(structure) -表功能,允许有效地转换和插入数据发送到
服务器与给定结构的表与另一种结构。

structure -以下格式发送到服务器的数据结构 'column1_name column1_type, column2_name column2_type, ...'.
例如, 'id UInt32, name String'.

此功能只能用于 INSERT SELECT 查询,只有一次,但其他行为像普通表函数
(例如,它可以用于子查询等。).

数据可以以任何方式像普通发送 INSERT 查询并传递任何可用 格式
必须在查询结束时指定(不像普通 INSERT SELECT).

这个功能的主要特点是,当服务器从客户端接收数据时,它同时将其转换
根据表达式中的列表 SELECT 子句并插入到目标表中。 临时表
不创建所有传输的数据。

  • test 表具有以下结构 (a String, b String)
    和数据 data.csv 具有不同的结构 (col1 String, col2 Date, col3 Int32). 查询插入
    从数据 data.csvtest 同时转换的表如下所示:
  1. $ cat data.csv | clickhouse-client --query="INSERT INTO test SELECT lower(col1), col3 * col3 FROM input('col1 String, col2 Date, col3 Int32') FORMAT CSV";
  • 如果 data.csv 包含相同结构的数据 test_structure 作为表 test 那么这两个查询是相等的:
  1. $ cat data.csv | clickhouse-client --query="INSERT INTO test FORMAT CSV"
  2. $ cat data.csv | clickhouse-client --query="INSERT INTO test SELECT * FROM input('test_structure') FORMAT CSV"

原始文章