depyronick / clickhouse-client

ClickHouse Client for NodeJS
https://clickhouse.js.org
MIT License
49 stars 11 forks source link

insert() failing with Syntax error message #24

Closed EricThompson-PeopleReign closed 1 year ago

EricThompson-PeopleReign commented 1 year ago

I'm calling await orm.insertPromise<Log>('logs', [log]) and getting this error:

Code: 62. DB::Exception: Syntax error: failed at position 1 ('{') (line 1, col 1): {"content":"itest-content-1zBFyEOtfl8x","conversation_uuid":"e21dd328-7cd0-44b9-b48c-eb23f972119d" ...

I went into the source code and added a console.log to see what it was sending the server: ClickHouseCLient.js:258

console.log(query, _data);

And get this:

INSERT INTO logs FORMAT JSONEachRow {"content":"itest-content-1zBFyEOtfl8x","conversation_uuid":"e21dd328-7cd0-44b9-b48c-eb23f972119d"}

I log into the ClickHouse server and run that query directly and it inserts just fine.

ClickHouse server version: version 23.3.1

@depyronick/clickhouse-client version: 2.0.1

EricThompson-PeopleReign commented 1 year ago

I did more investigation. This line overrides the data so that the INSERT INTO ${table} FORMAT JSONEachRow gets overridden: https://github.com/depyronick/clickhouse-client/blob/main/src/client/ClickHouseClient.ts#L351

kenvals commented 1 year ago

Added a fix to the code https://github.com/depyronick/clickhouse-client/pull/25

depyronick commented 1 year ago

@kenvals thanks for the contribution, you're fantastic. i just merged & deployed the new version as 2.0.2 please validate and close the issue if it's ok. thanks again.

depyronick commented 1 year ago

closing due to inactivity, feel free to reopen if still occurs