Skip to content

Fix empty results for sub-second timestamp queries#276

Merged
elffjs merged 1 commit intomainfrom
fix/datetime64-precision-timestamps
Mar 20, 2026
Merged

Fix empty results for sub-second timestamp queries#276
elffjs merged 1 commit intomainfrom
fix/datetime64-precision-timestamps

Conversation

@zer0stars
Copy link
Copy Markdown
Member

Summary

  • The clickhouse-go driver formats positional time.Time bind params (?) as toDateTime(...) which silently truncates to second precision. Our columns are DateTime64(6, 'UTC') (microsecond precision), and toStartOfInterval origins already used fromUnixTimestamp64Micro() with full precision — creating a mismatch that returned zero rows when callers passed timestamps with milliseconds (e.g. 2026-03-18T15:28:57.001Z).
  • Added dateTime64Micro() helper that formats time.Time as inline fromUnixTimestamp64Micro(int64) literals, bypassing the driver's truncation. No SQL injection risk — UnixMicro() always produces an int64.
  • Replaced all timestamp ? bind params across signal, event, segment detection, and batch queries with inline DateTime64(6) literals for consistent microsecond precision.

Test plan

  • All existing unit tests pass (go test ./internal/...)
  • go build ./... compiles cleanly
  • Verify with a real query using a millisecond-precision from timestamp (e.g. .001Z) that previously returned 0 signals

🤖 Generated with Claude Code

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>
elffjs
elffjs approved these changes Mar 20, 2026
@elffjs elffjs merged commit 4520644 into main Mar 20, 2026
4 checks passed
@elffjs elffjs deleted the fix/datetime64-precision-timestamps branch March 20, 2026 18:25
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.

2 participants