Skip to content

Date objects with non-zero milliseconds produce fractional timestamps rejected by {param:DateTime} #628

@jorgehermo9

Description

@jorgehermo9

Describe the bug

When Date objects' milliseconds is not zero, its serialization (

) 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

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions