8

I have a simple table:

CREATE TABLE t1
(
    v1 Int32, 
    a1 Array(Int32), 
    s2 Array(String)
) ENGINE = Memory

but can't figure out how to insert String array:

insert into t1 format CSV 1,"[1,2]","[a1,a2]"

fails with the following error:

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)
Kirill Solokhov
  • 400
  • 4
  • 16

2 Answers2

8

Sorry, re-read documentation and found that Strings in arrays should be wrapped by single quote.

 insert into t1 format CSV 1,"[1,2]","['a1','a2']"
Kirill Solokhov
  • 400
  • 4
  • 16
1

In case it helps anyone arriving here, there's a few non-standard CSV requirements for importing array columns, included object mapped columns too.

Arrays: []

  • Empty or Single entry are unquoted: [] or [75]
  • Multiple entry are quote wrapped: "[6,73,74]"

Objects: {}

  • Integer keys are always unquoted
  • String keys are always sinhgle quoted
  • Populated object {} are quote wrapped: "{95:26}" or "{'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 "

Example CSV raw - note the lack of double quotes.

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}"
Andy Gee
  • 3,149
  • 2
  • 29
  • 44