ClickHouse Functions
ClickHouse function reference for TypeScript developers
A curated set of common ClickHouse functions for analytics, with SQL and hypequery examples for date bucketing, aggregation, string manipulation, conditionals, and numeric bucketing.
Functions covered
27
Clusters
Date · Aggregate · String · Conditional · Math
Each page includes
SQL + query-builder examples
Date Functions
Date and time functions for bucketing, truncating, and formatting timestamps — the foundation of every ClickHouse analytics query.
toStartOfDay()Truncate a DateTime to midnight — the foundation of daily analytics bucketing.
View reference →
toStartOfWeek()Round a DateTime to the start of the week — weekly cohort and trend analysis.
View reference →
toStartOfMonth()Truncate a DateTime to the first day of the month for MoM reporting.
View reference →
toStartOfQuarter()Round a DateTime to the first day of the quarter for QoQ reporting.
View reference →
toStartOfInterval()Bucket by any arbitrary interval — 5-minute, hourly, bi-weekly, or custom.
View reference →
now()Return the current server DateTime — the anchor for relative time filters.
View reference →
toDate()Convert a string or DateTime to a ClickHouse Date value.
View reference →
formatDateTime()Format a DateTime as a string using strftime-style patterns.
View reference →
dateDiff()Count calendar-boundary crossings between two dates — not elapsed time, which is the gotcha everyone hits.
View reference →
Aggregate Functions
Aggregate functions for counting, summing, averaging, and estimating cardinality across millions of rows.
count()Count rows or non-NULL values — ClickHouse's fastest aggregate.
View reference →
uniq()Approximate distinct count — fast cardinality estimation for DAU and unique visitors.
View reference →
sum()Sum numeric values — revenue totals, event counts, and metric roll-ups.
View reference →
avg()Calculate the arithmetic mean — average order value, session duration, latency.
View reference →
quantile()Percentile estimates — p50, p95, p99 for latency and performance metrics.
View reference →
groupArray()Collect values into an array — session stitching, event sequences, and path analysis.
View reference →
min()Return the smallest value in a group — earliest signup, cheapest order, fastest response.
View reference →
max()Return the maximum value in a column — the go-to aggregate for peaks, latest timestamps, and largest orders.
View reference →
uniqExact()Count distinct values exactly — the precise, memory-heavy counterpart to uniq().
View reference →
String Functions
String manipulation functions for formatting display values, parsing, and building composite keys.
Conditional Functions
Conditional expressions for inline branching, NULL handling, and multi-way value selection.
if()Inline conditional — the ternary operator of ClickHouse SQL.
View reference →
multiIf()Multi-branch conditional — clean CASE WHEN replacement for status mapping.
View reference →
coalesce()Return the first non-NULL argument — the standard fix for Nullable(T) columns leaking into results.
View reference →
Math Functions
Math functions for rounding, integer arithmetic, and numeric bucketing.
Array Functions
Array functions for transforming, filtering, and unnesting array columns — including higher-order functions with lambda expressions.
Get started
Use common ClickHouse functions in typed TypeScript queries
hypequery generates a TypeScript schema from your live ClickHouse database. These examples show how to combine ClickHouse functions with the query builder, while using raw SQL expressions when the function is not wrapped by a dedicated helper.