Describe the bug
When Date objects' milliseconds is not zero, its serialization (
|
return milliseconds === 0 |
) produces fractional timestamps (e.g
1773935682.595), which are rejected by clickhouse service if the query param is of type
DateTime, with the following error:
Error: Value 1773935682.595 cannot be parsed as DateTime for query parameter 'startDate' because it isn't parsed completely: only 10 of 14 bytes was parsed: 1773935682.
The workaround is to use parameter type
DateTime64(3) in the query.
The official example at examples/query_with_parameter_binding.ts comments // or a Date object on the {var_datetime: DateTime} param, but this only works when date.getUTCMilliseconds() === 0. The client's formatQueryParams appends .XXX for non-zero ms, which DateTime rejects.
Note: using date_time_input_format: "best_effort" does not fix this.
Steps to reproduce
import { createClient } from '@clickhouse/client';
const client = createClient({ url: 'http://localhost:8123' });
const date = new Date('2025-03-19T10:30:00.500Z');
// FAILS: "Value 1742553000.500 cannot be parsed as DateTime"
await client.query({
query: `SELECT {d:DateTime} AS dt`,
query_params: { d: date },
});
// Works — DateTime64(3) accepts fractional timestamps
await client.query({
query: `SELECT {d:DateTime64(3)} AS dt`,
query_params: { d: date },
});
ClickHouse server
- ClickHouse Server version: 26.2.4.23
Describe the bug
When
Dateobjects' milliseconds is not zero, its serialization (clickhouse-js/packages/client-common/src/data_formatter/format_query_params.ts
Line 85 in 22e8610
1773935682.595), which are rejected by clickhouse service if the query param is of typeDateTime, with the following error:Error: Value 1773935682.595 cannot be parsed as DateTime for query parameter 'startDate' because it isn't parsed completely: only 10 of 14 bytes was parsed: 1773935682.The workaround is to use parameter type
DateTime64(3)in the query.The official example at
examples/query_with_parameter_binding.tscomments// or a Date objecton the{var_datetime: DateTime}param, but this only works whendate.getUTCMilliseconds() === 0. The client'sformatQueryParamsappends.XXXfor non-zero ms, whichDateTimerejects.Note: using
date_time_input_format: "best_effort"does not fix this.Steps to reproduce
ClickHouse server