Fix datetime parameter formating bug#184
Merged
alex-clickhouse merged 1 commit intomainfrom Jan 26, 2026
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug where DateTime parameters formatted as Unix timestamps near epoch (e.g., 0 for 1970-01-01 00:00:00) were rejected by ClickHouse's HTTP parameter parser. The fix changes HTTP parameter formatting to use ISO-formatted strings with appropriate timezone conversions instead of Unix timestamps.
Changes:
- Modified
HttpParameterFormatter.csto format DateTime/DateTime64 parameters as ISO strings with timezone conversions instead of Unix timestamps - Added comprehensive test coverage for DateTime/DateTime64 parameter handling across different timezones, DateTimeKind values, and edge cases including Unix epoch
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| ClickHouse.Driver/Formats/HttpParameterFormatter.cs | Replaced Unix timestamp formatting with ISO string formatting and timezone conversion logic for DateTime/DateTime64 parameters |
| ClickHouse.Driver.Tests/Types/TimezoneHandlingTests.cs | Added extensive test coverage for DateTime/DateTime64 parameter handling, timezone conversions, and edge cases including Unix epoch |
mzitnik
approved these changes
Jan 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Previously, when we wanted to preserve an instant we would simply send the number of ticks in UTC. That would get interpreted as UTC no matter what the column type, thus making everything consistent. There's a problem with this, however:
This is fine:
curl "http://localhost:8123/?param_dt=1705320000" -d "INSERT INTO test.datetime_test VALUES ({dt:DateTime})"But this throws:
curl "http://localhost:8123/?param_dt=0" -d "INSERT INTO test.datetime_test VALUES ({dt:DateTime})"Code: 41. DB::Exception: Cannot parse DateTime: value 0 cannot be parsed as DateTime for query parameter 'dt': at row 0: While executing ValuesBlockInputFormat. (CANNOT_PARSE_DATETIME) (version 25.12.1.649 (official build))This means that values near the epoch won't work, hence the bug reported here: #183
This PR changes the http parameter formatting approach to use strings instead, with the appropriate timezone adjustments based on the parameter type to maintain consistent behavior. Also adds a bunch more tests.
Note
Fixes DateTime HTTP parameter formatting
HttpParameterFormatterto emit ISO strings forDateTime/DateTime64, converting UTC/Local values into the parameter’s target timezone (or UTC) while sending Unspecified as-isFormatDateTimeInTargetTimezoneandFormatDateTime64InTargetTimezonefor timezone-aware ISO formattingExtensive test coverage added
Unspecified,Utc,Local, andDateTimeOffsetacross UTC,Europe/Amsterdam, and no-timezone columns0) and min range, plusDateTime64sub-second precision handlingWritten by Cursor Bugbot for commit b9f1a48. This will update automatically on new commits. Configure here.