Inserting decimal numbers using NodeJs client
kevcodez opened this issue · 3 comments
According to the docs, we're not supposed to use JSON strings but Tab/CSV separated with the following code
await client.insert({
table: 'my_table',
values: ['12.01\t5000000.405\n'],
format: 'TabSeparated',
})
However, this results in the error:
The client does not support JSON encoding in [TabSeparated] format.
If I take it correctly from the docs, it's not possibly to use TabSeparated / CsvSeparated to insert an array of strings?
Am I missing something here?
For "raw" formats, a stream is required as the input.
You could create it from an array, similarly to how it is done in this example: https://github.com/ClickHouse/clickhouse-js/blob/main/examples/node/stream_created_from_array_raw.ts#L23-L30.
CSV/TabSepated/CustomSeparated all work the same way.
This bit regarding decimals and JSON looks pretty outdated.
Maybe it was an issue a while ago when we started the project and wrote the initial docs, but as of the current CH versions, it's all good. I will update the docs.
So, it works fine with JSONEachRow. I pushed an example: https://github.com/ClickHouse/clickhouse-js/blob/main/examples/insert_decimals.ts
Docs will be updated when this PR is merged: ClickHouse/clickhouse-docs#2207