ClickHouse / clickhouse-js

Official JS client for ClickHouse DB
https://clickhouse.com
Apache License 2.0
217 stars 26 forks source link

Cannot insert Date even with date_time_input_format=best_effort #302

Closed maktouch closed 1 month ago

maktouch commented 1 month ago

Describe the bug

Steps to reproduce

1.

CREATE TABLE insert_js_date
      (id String, dt Date)
      ENGINE MergeTree()
      ORDER BY (id)

2.

await client.insert({
    table: 'insert_js_date',
    values: [
      {
        id: '42',
        dt: new Date(),
      },
    ],
    clickhouse_settings: {
      date_time_input_format: 'best_effort',
    },
    format: 'JSONEachRow',
  })

3.

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

slvrtrn commented 1 month ago

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

maktouch commented 1 month ago

Since the client inserts values without additional type conversion,

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