8

我有一个简单的表:

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)
4

2 回答 2

8

抱歉,重新阅读文档,发现数组中的字符串应该用单引号括起来。

 insert into t1 format CSV 1,"[1,2]","['a1','a2']"
于 2016-09-06T15:10:34.853 回答
0

如果它可以帮助任何到达这里的人,那么导入数组列有一些非标准的 CSV 要求,也包括对象映射列。

数组:[]

  • 空或单条目不加引号:[] 或 [75]
  • 多个条目被引号包裹:“[6,73,74]”

对象:{}

  • 整数键始终不加引号
  • 字符串键总是单引号
  • 填充对象 {} 用引号括起来:“{95:26}”或“{'a':26}”
描述 arr 字段 ardesc 对象字段 对象描述
空的 [] 没有引号 {} 没有引号
单个 int 键 [10] 没有引号 “{10:20}” 包裹在“
单键 ['十'] 单引号 “{'十':20}” '(键)并换行“
单个 str 键值 “{‘十’:‘二十’}” ' (key 和 val) 并包裹在 "
多 arr/ob “[6,73,74]” 包裹在“ “{6:6,73:8,74:4}” 包裹在“

CSV 原始示例 - 请注意缺少双引号。

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}"
于 2022-02-28T11:54:01.863 回答