---
title: "Working with Time Series Data in ClickHouse"
description: "ClickHouse handles time-series workloads with Date, DateTime and DateTime64 types (up to nanosecond precision, with per-column timezones) plus SQL functions for bucketing by period. toStartOfHour and toStartOfInterval group by fixed or custom intervals, WITH FILL fills empty buckets, dateDiff builds offset rolling windows, and bar() gives quick inline visuals."
url: "https://swe.quest/articles/working-with-time-series-data-in-clickhouse-d87ac55208de682a"
canonical: "https://clickhouse.com/blog/working-with-time-series-data-and-functions-ClickHouse"
source: "ClickHouse"
published: "2023-01-10"
difficulty: "medium"
kind: "How-to"
reading_minutes: 19
tags: ["analytics","sql","databases"]
---

# Working with Time Series Data in ClickHouse

A post on [ClickHouse](https://swe.quest/sources/clickhouse.md), published 2023-01-10, 19 min read, How-to. Original: [https://clickhouse.com/blog/working-with-time-series-data-and-functions-ClickHouse](https://clickhouse.com/blog/working-with-time-series-data-and-functions-ClickHouse)

## Summary

ClickHouse handles time-series workloads with Date, DateTime and DateTime64 types (up to nanosecond precision, with per-column timezones) plus SQL functions for bucketing by period. toStartOfHour and toStartOfInterval group by fixed or custom intervals, WITH FILL fills empty buckets, dateDiff builds offset rolling windows, and bar() gives quick inline visuals. Gauges can be filled forward with any() plus INTERPOLATE, and histogram() builds adaptive histograms. Examples run against a 1-billion-row Wikipedia pageviews table, where full scans complete in about 0.26 seconds.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Analytics & OLAP](https://swe.quest/tags/analytics.md) (Data & databases)
- [SQL](https://swe.quest/tags/sql.md) (Languages)
- [Databases](https://swe.quest/tags/databases.md) (Data & databases)

## Prerequisites

- SQL aggregation and GROUP BY ([easy posts on SQL](https://swe.quest/tags/sql.md?difficulty=easy))
- window functions

## Keywords

ClickHouse, MergeTree, DateTime64, WITH FILL, INTERPOLATE, Wikistat

## Related posts

- [Querying DateTimes in ClickHouse](https://swe.quest/articles/querying-datetimes-in-clickhouse-2cdba42b9ef08c40.md): ClickHouse · 2026-03-20 · Medium · 8 min read · SQL, Analytics & OLAP, Time & clocks
  ClickHouse's datetime functions cover rounding, filtering and duration calculations, demonstrated on about 3 million NYC taxi trips. toStartOfHour and toStartOfFifteenMinutes bucket timestamps, casting to ::Time groups or filters by time of day across all dates, and dateDiff computes trip durations to derive average speed, which falls from about 19 mph at 6am to about 11 mph by 8:30am. countIf with toDayOfWeek splits weekday and weekend trips, and the lag window function computes percentage change between windows. formatDateTime and bar make the output readable.
- [What's New in pg\_clickhouse - JSONB Support, SQL value functions, Streaming, and more](https://swe.quest/articles/what-s-new-in-pg-clickhouse-jsonb-support-sql-value-functions-streaming-and-more-ecb202cf6ff32298.md): ClickHouse · 2026-04-24 · Medium · 10 min read · PostgreSQL, Analytics & OLAP, Query engines, Memory management
  pg\_clickhouse, the Postgres foreign data wrapper for querying ClickHouse, now pushes down far more operations to ClickHouse.
- [ClickHouse vs BigQuery: Using ClickHouse to Serve Real-Time Queries on Top of BigQuery Data](https://swe.quest/articles/clickhouse-vs-bigquery-using-clickhouse-to-serve-real-time-queries-on-top-of-2c9e02d14f552560.md): ClickHouse · 2023-02-27 · Medium · 25 min read · Analytics & OLAP, Data pipelines, Cloud platforms, SQL
  ClickHouse can sit alongside BigQuery to serve sub-second, high-concurrency analytical queries for real-time applications, while BigQuery remains the warehouse for ad-hoc deep analysis.
- [ClickHouse and the MTA Data Challenge](https://swe.quest/articles/clickhouse-and-the-mta-data-challenge-dc13e535ba1ed542.md): ClickHouse · 2024-10-24 · Medium · 16 min read · Analytics & OLAP, Data pipelines, SQL
  Loading and cleaning the ~95 million-row NYC MTA subway turnstile dataset (2014–2022) in ClickHouse, using schema inference over S3, a staging table, and an optimized schema with LowCardinality strings, a combined DateTime column, UInt32 counters, sorted line-name arrays and a (station, date\_time) ordering key.
- [Accelerating ClickHouse queries on JSON data for faster Bluesky insights](https://swe.quest/articles/accelerating-clickhouse-queries-on-json-data-for-faster-bluesky-insights-cce6ed7a467f6449.md): ClickHouse · 2025-03-19 · Medium · 29 min read · Analytics & OLAP, Performance engineering, SQL, Databases
  Incremental materialized views feeding AggregatingMergeTree tables cut ClickHouse dashboard queries over 4+ billion Bluesky JSON documents (1.6 TiB) from 44–56 seconds to 3–7 ms. Partial aggregation states are computed only for newly inserted rows and merged in the background, so the pre-aggregated tables stay tiny (e.g. 892 rows, 11 KiB) and constant-size regardless of source growth.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
