---
title: "ClickHouse forecasting and anomaly detection with time series foundation models"
description: "TimesFM 3.0, a pretrained time-series foundation model, can be called from ClickHouse SQL via executable Python UDFs that forward arrays to an HTTP model server, giving zero-shot forecasts and anomaly scores without per-series training."
url: "https://swe.quest/articles/clickhouse-forecasting-and-anomaly-detection-with-time-series-foundation-models-71a24c218275d2ec"
canonical: "https://clickhouse.com/blog/clickhouse-time-series-foundation-models"
source: "ClickHouse"
published: "2026-11-17"
difficulty: "medium"
kind: "How-to"
reading_minutes: 11
tags: ["analytics","machine-learning","inference","sql"]
---

# ClickHouse forecasting and anomaly detection with time series foundation models

A post on [ClickHouse](https://swe.quest/sources/clickhouse.md), published 2026-11-17, 11 min read, How-to. Original: [https://clickhouse.com/blog/clickhouse-time-series-foundation-models](https://clickhouse.com/blog/clickhouse-time-series-foundation-models)

## Summary

TimesFM 3.0, a pretrained time-series foundation model, can be called from ClickHouse SQL via executable Python UDFs that forward arrays to an HTTP model server, giving zero-shot forecasts and anomaly scores without per-series training. SQL handles aggregation, ordering and time bucketing. aiForecast returns median, q10–q90 bounds and nine native quantiles per step, and aiDetectAnomalies scores rolling held-out windows by normalized forecast error. On Walmart M5 store sales, adding a known-future Christmas event flag as a covariate dropped Christmas anomaly scores below the threshold in nine of ten stores (e.g. TX\_2 from 8.65 to 2.71). The weights carry non-commercial restrictions and the demo is for local evaluation only.

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)
- [Machine learning](https://swe.quest/tags/machine-learning.md) (AI & ML)
- [Inference & serving](https://swe.quest/tags/inference.md) (AI & ML)
- [SQL](https://swe.quest/tags/sql.md) (Languages)

## Prerequisites

- ClickHouse SQL and array functions ([easy posts on Analytics & OLAP](https://swe.quest/tags/analytics.md?difficulty=easy))
- time series forecasting basics
- prediction intervals and quantiles

## Keywords

ClickHouse, TimesFM, M5 dataset, executable UDF, Docker Compose, LogHouse

## Related posts

- [Forecasting Using ClickHouse Machine Learning Functions](https://swe.quest/articles/forecasting-using-clickhouse-machine-learning-functions-69c536e4a757b31c.md): ClickHouse · 2023-10-26 · Medium · 9 min read · Analytics & OLAP, Machine learning, SQL
  ClickHouse's built-in stochasticLinearRegression and evalMLMethod functions can fit and apply time-series forecasting models entirely in SQL, with no Python or R. Using monthly flight passenger data, a log-transformed target is regressed on a linear trend plus 12 month dummy variables, with no intercept to avoid the dummy variable trap.
- [TimesFM-3: A zero-shot foundation model for multivariate forecasting](https://swe.quest/articles/timesfm-3-a-zero-shot-foundation-model-for-multivariate-forecasting-c2421e383bcd85af.md): Google Research · 2026-08-31 · Hard · 6 min read · Machine learning, Model training, Inference & serving
  TimesFM-3 is a 330M-parameter decoder-only transformer pre-trained on over 1 trillion real and synthetic time points that does zero-shot multivariate forecasting, supporting multiple targets, past-only covariates and known-future covariates.
- [Introducing TabFM: A zero-shot foundation model for tabular data](https://swe.quest/articles/introducing-tabfm-a-zero-shot-foundation-model-for-tabular-data-3b60f0bd6faee92a.md): Google Research · 2026-06-30 · Easy · 5 min read · Machine learning, Model training, Analytics & OLAP
  TabFM is a foundation model that treats tabular classification and regression as in-context learning, so it predicts on an unseen table in a single forward pass with no training, hyperparameter tuning or feature engineering.
- [What's new in ClickStack - April 2026](https://swe.quest/articles/what-s-new-in-clickstack-april-2026-8ecf13fb74019726.md): ClickHouse · 2026-05-19 · Medium · 13 min read · Observability, Analytics & OLAP, SQL, Performance engineering
  ClickStack's April 2026 release adds alerts driven by arbitrary ClickHouse SQL, so rolling baselines and standard-deviation anomaly checks can be written with window functions and fire when the query returns 1.
- [Executable UDFs are now in public beta on ClickHouse Cloud](https://swe.quest/articles/executable-udfs-are-now-in-public-beta-on-clickhouse-cloud-89bd8753f4dda600.md): ClickHouse · 2026-05-30 · Medium · 14 min read · Analytics & OLAP, Inference & serving, Machine learning, SQL, Python
  Executable UDFs are in public beta on ClickHouse Cloud: you upload a zipped Python function with its model files, and ClickHouse runs it in a pool of long-lived sandboxed processes that can be called from SQL, including inside materialized views.

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)
