Skip to content

Drop sub-seconds for DateTime query params while preserving DateTime64 precision#777

Draft
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-date-millisecond-serialization
Draft

Drop sub-seconds for DateTime query params while preserving DateTime64 precision#777
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-date-millisecond-serialization

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 29, 2026

Summary

Date query params are serialized as fractional Unix timestamps (e.g. 1742553000.500) whenever milliseconds are non-zero. DateTime/DateTime32 reject the fractional part (Value ... cannot be parsed as DateTime ... isn't parsed completely), while DateTime64 requires it. Since formatQueryParams only saw the value, it could not pick the right encoding (#628).

The client now infers the declared parameter type from the query's {name:Type} placeholder and drops the sub-second part only for second-precision types, keeping it for DateTime64.

const date = new Date('2025-03-19T10:30:00.500Z')

// before: "Value 1742553000.500 cannot be parsed as DateTime"
// after:  '2025-03-19 10:30:00'
await client.query({ query: `SELECT {d:DateTime} AS dt`, query_params: { d: date } })

// unchanged: '2025-03-19 10:30:00.500'
await client.query({ query: `SELECT {d:DateTime64(3)} AS dt`, query_params: { d: date } })

Changes

  • format_query_params.ts: formatQueryParams accepts an optional type; shouldTruncateDateToSeconds truncates when the type matches /DateTime/ but not /DateTime64/. Threaded through arrays/tuples/maps so nested Dates follow the container type. Unknown type → previous millisecond behavior (no regression).
  • url.ts: toSearchParams parses each param's type from the query (getQueryParamType, whitespace-tolerant, regex-escaped name) and forwards it. Added a query_in_url flag to decouple type detection from URL inclusion — passing the SQL in both the URL and the body makes the server concatenate and reject it.
  • Connections (node & web): query()/web exec() pass query with query_in_url: false; node runExec gates URL inclusion on sendQueryInParams.

Checklist

  • Unit and integration tests covering the common scenarios were added
  • A human-readable description of the changes was provided to include in CHANGELOG

@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copilot AI changed the title [WIP] Fix serialization of Date objects with non-zero milliseconds Drop sub-seconds for DateTime query params while preserving DateTime64 precision May 29, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 29, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants