在 ClickHouse db 中通过 CSV 格式插入字符串数组
Inserting String Array through CSV format in ClickHouse db
我有一个简单的table:
CREATE TABLE t1
(
v1 Int32,
a1 Array(Int32),
s2 Array(String)
) ENGINE = Memory
但不知道如何插入字符串数组:
insert into t1 format CSV 1,"[1,2]","[a1,a2]"
失败并出现以下错误:
Exception on client:
Code: 26. DB::Exception: Cannot parse quoted string: expected opening quote:
Could not print diagnostic info because two last rows aren't in buffer (rare case)
: (at row 1)
抱歉,重新阅读文档,发现数组中的字符串应该用单引号括起来。
insert into t1 format CSV 1,"[1,2]","['a1','a2']"
如果它能帮助到这里的任何人,导入数组列有一些 non-standard CSV 要求,也包括对象映射列。
数组:[]
- 空条目或单个条目未加引号:[] 或 [75]
- 多个条目用引号括起来:“[6,73,74]”
对象:{}
- 整数键总是不带引号
- 字符串键总是单引号
- 填充对象 {} 被引号包裹:“{95:26}”或“{'a':26}”
desc
arrField
arrdesc
objField
objDesc
empty
[]
no quotes
{}
no quotes
single int key
[10]
no quotes
"{10:20}"
wrap in "
single str key
['ten']
single quote
"{'ten':20}"
' (key) and wrap in "
single str key val
"{'ten':'twenty'}"
' (key and val) and wrap in "
multi arr/ob
"[6,73,74]"
wrap in "
"{6:6,73:8,74:4}"
wrap in "
示例 CSV raw - 注意缺少双引号。
one,two,three
[75],"{95:26}","{'a':66}"
[75],"{75:2}",{}
"[6,73,74]","{6:6,73:8,74:4}","{'a':8,'b':9,'c':6}"
"[340,272,205]","{340:2,272:2,205:2,206:2,208:2,141:2,142:4}","{'a':7}"
[204],"{204:2}",{}
"[142,141,73]","{142:2,141:4,73:4}","{'a':2,'b':4}"
[74],"{74:20}","{'a':36}"
"[5,74,73]","{5:2,74:10,73:8}","{'a':17}"
我有一个简单的table:
CREATE TABLE t1
(
v1 Int32,
a1 Array(Int32),
s2 Array(String)
) ENGINE = Memory
但不知道如何插入字符串数组:
insert into t1 format CSV 1,"[1,2]","[a1,a2]"
失败并出现以下错误:
Exception on client:
Code: 26. DB::Exception: Cannot parse quoted string: expected opening quote:
Could not print diagnostic info because two last rows aren't in buffer (rare case)
: (at row 1)
抱歉,重新阅读文档,发现数组中的字符串应该用单引号括起来。
insert into t1 format CSV 1,"[1,2]","['a1','a2']"
如果它能帮助到这里的任何人,导入数组列有一些 non-standard CSV 要求,也包括对象映射列。
数组:[]
- 空条目或单个条目未加引号:[] 或 [75]
- 多个条目用引号括起来:“[6,73,74]”
对象:{}
- 整数键总是不带引号
- 字符串键总是单引号
- 填充对象 {} 被引号包裹:“{95:26}”或“{'a':26}”
desc | arrField | arrdesc | objField | objDesc |
---|---|---|---|---|
empty | [] | no quotes | {} | no quotes |
single int key | [10] | no quotes | "{10:20}" | wrap in " |
single str key | ['ten'] | single quote | "{'ten':20}" | ' (key) and wrap in " |
single str key val | "{'ten':'twenty'}" | ' (key and val) and wrap in " | ||
multi arr/ob | "[6,73,74]" | wrap in " | "{6:6,73:8,74:4}" | wrap in " |
示例 CSV raw - 注意缺少双引号。
one,two,three
[75],"{95:26}","{'a':66}"
[75],"{75:2}",{}
"[6,73,74]","{6:6,73:8,74:4}","{'a':8,'b':9,'c':6}"
"[340,272,205]","{340:2,272:2,205:2,206:2,208:2,141:2,142:4}","{'a':7}"
[204],"{204:2}",{}
"[142,141,73]","{142:2,141:4,73:4}","{'a':2,'b':4}"
[74],"{74:20}","{'a':36}"
"[5,74,73]","{5:2,74:10,73:8}","{'a':17}"