ClickHouse/clickhouse-js

Cannot insert Date even with date_time_input_format=best_effort

maktouch opened this issue · 2 comments

Describe the bug

Steps to reproduce

CREATE TABLE insert_js_date
      (id String, dt Date)
      ENGINE MergeTree()
      ORDER BY (id)
await client.insert({
    table: 'insert_js_date',
    values: [
      {
        id: '42',
        dt: new Date(),
      },
    ],
    clickhouse_settings: {
      date_time_input_format: 'best_effort',
    },
    format: 'JSONEachRow',
  })
ClickHouseError: Cannot parse input: expected '"' before: 'T23:23:52.466Z"}\n': (while reading the value of key dt): (at row 1)
: While executing ParallelParsingBlockInputFormat. 
}

Expected behaviour

I expected this to work. It works when I format I use new Date().toISOString().substring(0, 10)... but it kinda should do this automatically? It works when the column type is DateTime though.

ClickHouse server

  • ClickHouse Server version: 24.5.5

Date(32) can only be inserted as strings, since the Date object is serialized including the time part and apparently that does not work well with CH even with best_effort setting.
This is mentioned in the docs: https://clickhouse.com/docs/en/integrations/language-clients/javascript#datedate32-types-caveats

Since the client inserts values without additional type conversion,

Ah I see. I had no clue there was no transform. Thanks for the feedback!