Fix empty results for sub-second timestamp queries#276
Merged
Conversation
The clickhouse-go driver formats positional time.Time bind params as toDateTime() which truncates to second precision. This caused a mismatch with DateTime64(6) columns and the toStartOfInterval origin (which used fromUnixTimestamp64Micro with full precision), resulting in zero rows returned when callers passed timestamps with milliseconds. Replace all timestamp ? bind params with inline fromUnixTimestamp64Micro() literals to preserve microsecond precision end-to-end. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
Summary
clickhouse-godriver formats positionaltime.Timebind params (?) astoDateTime(...)which silently truncates to second precision. Our columns areDateTime64(6, 'UTC')(microsecond precision), andtoStartOfIntervalorigins already usedfromUnixTimestamp64Micro()with full precision — creating a mismatch that returned zero rows when callers passed timestamps with milliseconds (e.g.2026-03-18T15:28:57.001Z).dateTime64Micro()helper that formatstime.Timeas inlinefromUnixTimestamp64Micro(int64)literals, bypassing the driver's truncation. No SQL injection risk —UnixMicro()always produces anint64.?bind params across signal, event, segment detection, and batch queries with inline DateTime64(6) literals for consistent microsecond precision.Test plan
go test ./internal/...)go build ./...compiles cleanlyfromtimestamp (e.g..001Z) that previously returned 0 signals🤖 Generated with Claude Code