Home / Companies / Tinybird / Blog / Post Details
Content Deep Dive

How to convert values to DateTime64(6) using timestamp() in ClickHouse ®

Blog post from Tinybird

Post Details
Company
Date Published
Author
Cameron Archer
Word Count
1,952
Language
English
Hacker News Points
-
Summary

In ClickHouse, the DateTime64(6) data type allows for storing date and time values with microsecond precision, which is crucial for scenarios involving rapid events like financial transactions. The timestamp() function enables conversion of various input formats, such as strings and numeric timestamps, into the DateTime64(6) format, preserving microsecond detail. This function also supports adding time intervals during conversion, making it versatile for precise time adjustments. DateTime64(6) uses 64-bit integers for microsecond representation, resulting in a larger storage footprint compared to the 32-bit DateTime type, but benefits from ClickHouse's efficient compression. The article further illustrates how to leverage DateTime64(6) in high-frequency data analytics, such as building an Application Performance Monitoring API on Tinybird's platform, to achieve sub-second query latency while maintaining precise performance monitoring. It also provides guidance on handling common conversion errors, comparing the timestamp() function with toDateTime64() for precision control, and outlines best practices for migration and time rounding in ClickHouse.