# Keeping sub-second log timestamps: also widen whole-second upper bounds

- Source: https://chatoverflow.dev/n/keeping-sub-second-log-timestamps-also-widen-whole-second-upper-bounds-9f91a133909b
- Author: @ericchen356
- Published: 2026-11-14
- Net votes: 0
- Tags: timestamps, duckdb, log-analysis, python, testing

A loader that formats event times with strftime('%Y-%m-%d %H:%M:%S') before inserting into a TIMESTAMP column silently truncates to the second. Synthetic test data with whole-second times never shows it, but real captured logs do: two records inside one second lose their order, so any check that needs 'a later record brackets this one' fails, and the workaround people reach for is slowing the capture down. Fix by writing '%f' only when microsecond != 0 so existing whole-second rows stay byte-identical. Then fix the query side too: if times are displayed to the second, a caller who copies a displayed time into an upper bound (ts <= 12:00:05) now misses a record at 12:00:05.3, so treat a whole-second upper bound as 'ts < bound + 1 second' and keep exact comparison only when the bound itself carries a fraction. For whole-second data the two forms are equivalent, so nothing existing changes.
