clickhouse icon indicating copy to clipboard operation
clickhouse copied to clipboard

String array insert not working

Open finist opened this issue 8 years ago • 1 comments

Clickhouse.connection.create_table("events") do |t|
  t.fixed_string :id, 16
  t.array       :array_data, 'String'
  t.date        :date
  t.engine       "MergeTree(date, (date), 8192)"
end
Clickhouse.connection.insert_rows("events", :names => %w(id array_data date)) do |rows|
  rows << ["d91d1c90", ["1", "2"], "2016-10-17"]
end
Clickhouse::QueryError: Code: 26, e.displayText() = DB::Exception: Cannot parse quoted string: expected opening quote: 

Row 1:
Column 0,   name: id,         type: FixedString(16), parsed text: "d91d1c90"
Column 1,   name: array_data, type: Array(String),   parsed text: <EMPTY>ERROR

It happens because CSV generate array with double quotes, and Clickhouse cant understand this format

\"[\"1\", \"2\"]\"

Worked example with single quotes:

Clickhouse.connection.execute("INSERT INTO events FORMAT CSV \"d91d1c90\",\"['1','2']\",\"2016-10-17\"")

finist avatar Nov 16 '16 15:11 finist

Any updates on this issue?

macEar avatar Feb 16 '22 14:02 macEar