You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using clickhouse-js to insert rows into a table. For timestamps, I'm using DateTime64(3, 'UTC'). However, the client seems to have a problem with Date objects: Cannot parse input: expected '"' before: 'Z","message":"{\\"created_at\\":\\"2023-12-06T10:54:48.000Z\\",\\"modified_at\\":\\"2023-12-': (while reading the value of key created_at): While executing ParallelParsingBlockInputFormat: (at row 1) ... ,"error":{"code":"27","type":"CANNOT_PARSE_INPUT_ASSERTION_FAILED"}
When I convert the Date objects to strings and remove the timezone part, it works:
import{ClickHouseClient}from'@clickhouse/client';import{InsertClient}from'./InsertClient';importmomentfrom'moment';exportclassClickHouseInsertClientimplementsInsertClient{publicconstructor(privateclickHouseClient: ClickHouseClient){}publicasyncinsertObjects(tableName: string,objects: object[]): Promise<void>{for(constobjectofobjects){for(constkeyofObject.keys(object)){object[key]=this.sanitizeValue(object[key]);}}awaitthis.clickHouseClient.insert({table: tableName,values: objects,format: 'JSONEachRow'});}privatesanitizeValue(value: unknown): unknown{// ClickHouse can't handle the timezone part (Z or offset +00:00) in the date stringif(valueinstanceofDate){returnmoment(value).format('YYYY-MM-DD HH:mm:ss.SSS');}returnvalue;}}
Environment
Client version: 0.2.6
Language version:
OS: Linux
ClickHouse server
ClickHouse Server version: 23.9.1.1854
The text was updated successfully, but these errors were encountered:
aimfeld
changed the title
Client insert() cannot handle Date objects with milliseconds and timezone
Client insert() cannot handle Date objects with timezone
Dec 6, 2023
@mshustov, thanks! It works very well with DateTime fields (see the test). Date/Date32 are not parsed properly with this setting, though; I think we can revisit it in the scope of #216
@aimfeld, I added an example that should work for your use-case. Feel free to re-open or DM in the community Slack if you encounter any issues.
I'm using clickhouse-js to insert rows into a table. For timestamps, I'm using
DateTime64(3, 'UTC')
. However, the client seems to have a problem with Date objects:Cannot parse input: expected '"' before: 'Z","message":"{\\"created_at\\":\\"2023-12-06T10:54:48.000Z\\",\\"modified_at\\":\\"2023-12-': (while reading the value of key created_at): While executing ParallelParsingBlockInputFormat: (at row 1) ... ,"error":{"code":"27","type":"CANNOT_PARSE_INPUT_ASSERTION_FAILED"}
When I convert the Date objects to strings and remove the timezone part, it works:
Environment
ClickHouse server
The text was updated successfully, but these errors were encountered: