导出时删除 Clickhouse 中字符串的引号
Remove quotes for String in Clickhouse while exporting
我正在尝试从 clickhouse cli 将数据导出到 csv。
我有一个字符串字段,当导出为 CSV 时,该字段周围有引号。
我想在没有 quotes
的情况下导出,但找不到任何可以设置的设置。
我经历了 https://clickhouse.yandex/docs/en/interfaces/formats 但值部分提到了
Strings, dates, and dates with times are output in quotes
虽然 JSON 他们有一个标志要设置用于删除 Int64 和 UInt64 周围的引号
For compatibility with JavaScript, Int64 and UInt64 integers are enclosed in double quotes by default. To remove the quotes, you can set the configuration parameter output_format_json_quote_64bit_integers to 0.
我想知道 CSV 中的字符串是否也有这种标志。
我正在使用以下命令导出
clickhouse client --multiquery --host="localhost" --port="9000" --query="SELECT field1, field2 from tableName format CSV" > /data/content.csv
如果没有任何效果,我想尝试从 shell 中删除引号作为最后一件事。
如果我能在生成 CSV 时删除引号,请提供任何帮助。
不,没有。但是,您可以通过 arrayStringConcat
轻松实现此目的。
SELECT arrayStringConcat([toString(field1), toString(field2)], ',') from tableName format TSV;
编辑
为了使 Nullable
输出为空字符串,您可能需要 if
函数。
if(isNull(field1), '', assumeNotNull(field1))
这适用于任何类型,而 assumeNotNull
仅适用于 String
我正在尝试从 clickhouse cli 将数据导出到 csv。
我有一个字符串字段,当导出为 CSV 时,该字段周围有引号。
我想在没有 quotes
的情况下导出,但找不到任何可以设置的设置。
我经历了 https://clickhouse.yandex/docs/en/interfaces/formats 但值部分提到了
Strings, dates, and dates with times are output in quotes
虽然 JSON 他们有一个标志要设置用于删除 Int64 和 UInt64 周围的引号
For compatibility with JavaScript, Int64 and UInt64 integers are enclosed in double quotes by default. To remove the quotes, you can set the configuration parameter output_format_json_quote_64bit_integers to 0.
我想知道 CSV 中的字符串是否也有这种标志。
我正在使用以下命令导出
clickhouse client --multiquery --host="localhost" --port="9000" --query="SELECT field1, field2 from tableName format CSV" > /data/content.csv
如果没有任何效果,我想尝试从 shell 中删除引号作为最后一件事。
如果我能在生成 CSV 时删除引号,请提供任何帮助。
不,没有。但是,您可以通过 arrayStringConcat
轻松实现此目的。
SELECT arrayStringConcat([toString(field1), toString(field2)], ',') from tableName format TSV;
编辑
为了使 Nullable
输出为空字符串,您可能需要 if
函数。
if(isNull(field1), '', assumeNotNull(field1))
这适用于任何类型,而 assumeNotNull
仅适用于 String