About TimescaleDB hyperfunctions
Use hyperfunctions for enhanced real-time analytics
TimescaleDB hyperfunctions package common time-series analytics patterns (percentiles, counters, sessionization, approximate distincts) as composable SQL functions instead of hand-rolled window logic. They help across IoT, IT telemetry, product analytics, finance, and many other event-heavy domains. Hyperfunctions aim to keep those queries fast enough to feel real time.
Tiger Cloud includes all hyperfunctions by default, while self-hosted TimescaleDB includes a subset of them. For additional hyperfunctions, install the TimescaleDB Toolkit PostgreSQL extension.
Available hyperfunctions
Section titled “Available hyperfunctions”Here is a list of all the hyperfunctions provided by TimescaleDB. Hyperfunctions
with a tick in the Toolkit column require an installation of TimescaleDB Toolkit for self-hosted deployments. Hyperfunctions
with a tick in the Experimental column are still under development.
Experimental features could have bugs. They might not be backwards compatible, and could be removed in future releases. Use these features at your own risk, and do not use any experimental features in production.
When you upgrade the timescaledb extension, the experimental schema is removed
by default. To use experimental features after an upgrade, you need to add the
experimental schema again.
Approximate count distinct functions
Section titled “Approximate count distinct functions”| Type | Name | Toolkit | Experimental |
|---|---|---|---|
| Aggregate | hyperloglog() | ✅ | |
| Alternate aggregate | approx_count_distinct() | ✅ | |
| Accessor | distinct_count() | ✅ | |
stderror() | ✅ | ||
| Rollup | rollup() | ✅ |
Counters and gauges functions
Section titled “Counters and gauges functions”counter_agg() functions
| Type | Name | Toolkit | Experimental |
|---|---|---|---|
| Aggregate | counter_agg() | ✅ | |
| Accessor | corr() | ✅ | |
counter_zero_time() | ✅ | ||
delta() | ✅ | ||
extrapolated_delta() | ✅ | ||
extrapolated_rate() | ✅ | ||
first_time() | ✅ | ||
first_val() | ✅ | ||
idelta_left() | ✅ | ||
idelta_right() | ✅ | ||
intercept() | ✅ | ||
interpolated_delta() | ✅ | ||
interpolated_rate() | ✅ | ||
irate_left() | ✅ | ||
irate_right() | ✅ | ||
last_time() | ✅ | ||
last_val() | ✅ | ||
num_changes() | ✅ | ||
num_elements() | ✅ | ||
num_resets() | ✅ | ||
rate() | ✅ | ||
slope() | ✅ | ||
time_delta() | ✅ | ||
| Rollup | rollup() | ✅ | |
| Mutator | with_bounds() | ✅ |
gauge_agg() functions
| Type | Name | Toolkit | Experimental |
|---|---|---|---|
| Aggregate | gauge_agg() | ✅ | ✅ |
| Accessor | corr() | ✅ | ✅ |
delta() | ✅ | ✅ | |
extrapolated_delta() | ✅ | ✅ | |
extrapolated_rate() | ✅ | ✅ | |
gauge_zero_time() | ✅ | ✅ | |
idelta_left() | ✅ | ✅ | |
idelta_right() | ✅ | ✅ | |
intercept() | ✅ | ✅ | |
interpolated_delta() | ✅ | ✅ | |
interpolated_rate() | ✅ | ✅ | |
irate_left() | ✅ | ✅ | |
irate_right() | ✅ | ✅ | |
num_changes() | ✅ | ✅ | |
num_elements() | ✅ | ✅ | |
slope() | ✅ | ✅ | |
rate() | ✅ | ✅ | |
time_delta() | ✅ | ✅ | |
| Rollup | rollup() | ✅ | ✅ |
| Mutator | with_bounds() | ✅ | ✅ |
Downsampling functions
Section titled “Downsampling functions”| Type | Name | Toolkit | Experimental |
|---|---|---|---|
| Function | asap_smooth() | ✅ | |
lttb() | ✅ | ||
gp_lttb() | ✅ | ✅ |
Financial analysis functions
Section titled “Financial analysis functions”candlestick_agg() functions
| Type | Name | Toolkit | Experimental |
|---|---|---|---|
| Aggregate | candlestick_agg() | ✅ | |
| Pseudo aggregate | candlestick() | ✅ | |
| Accessor | close() | ✅ | |
close_time() | ✅ | ||
high() | ✅ | ||
high_time() | ✅ | ||
low() | ✅ | ||
low_time() | ✅ | ||
open() | ✅ | ||
open_time() | ✅ | ||
volume() | ✅ | ||
vwap() | ✅ | ||
| Rollup | rollup() | ✅ |
Frequency analysis functions
Section titled “Frequency analysis functions”count_min_sketch() functions
| Type | Name | Toolkit | Experimental |
|---|---|---|---|
| Aggregate | count_min_sketch() | ✅ | ✅ |
| Accessor | approx_count() | ✅ | ✅ |
freq_agg() functions
| Type | Name | Toolkit | Experimental |
|---|---|---|---|
| Aggregate | freq_agg() | ✅ | ✅ |
| Accessor | into_values() | ✅ | |
max_frequency() | ✅ | ||
min_frequency() | ✅ | ||
topn() | ✅ | ||
| Alternate aggregate | mcv_agg() | ✅ | |
| Rollup | rollup() | ✅ |
Gapfilling functions
Section titled “Gapfilling functions”| Type | Name | Toolkit | Experimental |
|---|---|---|---|
| Bucket | time_bucket_gapfill() | ||
| Interpolator | interpolate() | ||
locf() |
Minimum and maximum functions
Section titled “Minimum and maximum functions”max_n() functions
| Type | Name | Toolkit | Experimental |
|---|---|---|---|
| Aggregate | max_n() | ✅ | |
| Accessor | into_values() | ✅ | |
into_array() | ✅ | ||
| Rollup | rollup() | ✅ |
max_n_by() functions
| Type | Name | Toolkit | Experimental |
|---|---|---|---|
| Aggregate | max_n_by() | ✅ | |
| Accessor | into_values() | ✅ | |
| Rollup | rollup() | ✅ |
min_n() functions
| Type | Name | Toolkit | Experimental |
|---|---|---|---|
| Aggregate | min_n() | ✅ | |
| Accessor | into_array() | ✅ | |
into_values() | ✅ | ||
| Rollup | rollup() | ✅ |
min_n_by() functions
| Type | Name | Toolkit | Experimental |
|---|---|---|---|
| Aggregate | min_n_by() | ✅ | |
| Accessor | into_values() | ✅ | |
| Rollup | rollup() | ✅ |
Percentile approximation functions
Section titled “Percentile approximation functions”tdigest() functions
| Type | Name | Toolkit | Experimental |
|---|---|---|---|
| Aggregate | tdigest() | ✅ | |
| Accessor | approx_percentile() | ✅ | |
approx_percentile_rank() | ✅ | ||
mean() | ✅ | ||
num_vals() | ✅ | ||
| Rollup | rollup() | ✅ |
percentile_agg() / uddsketch() functions
| Type | Name | Toolkit | Experimental |
|---|---|---|---|
| Aggregate | percentile_agg() | ✅ | |
| Alternate aggregate | uddsketch() | ✅ | |
| Accessor | approx_percentile() | ✅ | |
approx_percentile_rank() | ✅ | ||
error() | ✅ | ||
mean() | ✅ | ||
num_vals() | ✅ | ||
| Rollup | rollup() | ✅ |
Saturating math functions
Section titled “Saturating math functions”| Type | Name | Toolkit | Experimental |
|---|---|---|---|
| Function | saturating_add() | ✅ | |
saturating_add_pos() | ✅ | ||
saturating_mul() | ✅ | ||
saturating_sub() | ✅ | ||
saturating_sub_pos() | ✅ |
State tracking functions
Section titled “State tracking functions”compact_state_agg() functions
| Type | Name | Toolkit | Experimental |
|---|---|---|---|
| Aggregate | compact_state_agg() | ✅ | ✅ |
| Accessor | duration_in() | ✅ | ✅ |
interpolated_duration_in() | ✅ | ✅ | |
into_values() | ✅ | ✅ | |
| Rollup | rollup() | ✅ | ✅ |
heartbeat_agg() functions
| Type | Name | Toolkit | Experimental |
|---|---|---|---|
| Aggregate | heartbeat_agg() | ✅ | |
| Accessor | dead_ranges() | ✅ | |
downtime() | ✅ | ||
interpolate() | ✅ | ||
interpolated_downtime() | ✅ | ||
interpolated_uptime() | ✅ | ||
live_ranges() | ✅ | ||
num_gaps() | ✅ | ||
live_at() | ✅ | ||
num_live_ranges() | ✅ | ||
trim_to() | ✅ | ||
uptime() | ✅ | ||
| Rollup | rollup() | ✅ |
state_agg() functions
| Type | Name | Toolkit | Experimental |
|---|---|---|---|
| Aggregate | state_agg() | ✅ | |
| Accessor | duration_in() | ✅ | |
interpolated_duration_in() | ✅ | ||
interpolated_state_periods() | ✅ | ||
interpolated_state_timeline() | ✅ | ||
into_values() | ✅ | ||
state_at() | ✅ | ||
state_periods() | ✅ | ||
state_timeline() | ✅ | ||
| Rollup | rollup() | ✅ |
Statistical and regression analysis functions
Section titled “Statistical and regression analysis functions”stats_agg() (one variable) functions
| Type | Name | Toolkit | Experimental |
|---|---|---|---|
| Aggregate | stats_agg() (one variable) | ✅ | |
| Accessor | average() | ✅ | |
num_vals() | ✅ | ||
kurtosis() | ✅ | ||
skewness() | ✅ | ||
stddev() | ✅ | ||
sum() | ✅ | ||
variance() | ✅ | ||
| Rollup | rolling() | ✅ | |
rollup() | ✅ |
stats_agg() (two variables) functions
| Type | Name | Toolkit | Experimental |
|---|---|---|---|
| Aggregate | stats_agg() (two variables) | ✅ | |
| Accessor | average_y(), average_x() | ✅ | |
corr() | ✅ | ||
covariance() | ✅ | ||
determination_coeff() | ✅ | ||
intercept() | ✅ | ||
kurtosis_y(), kurtosis_x() | ✅ | ||
num_vals() | ✅ | ||
skewness_y(), skewness_x() | ✅ | ||
slope() | ✅ | ||
stddev_y(), stddev_x() | ✅ | ||
sum_y(), sum_x() | ✅ | ||
variance_y(), variance_x() | ✅ | ||
x_intercept() | ✅ | ||
| Rollup | rolling() | ✅ | |
rollup() | ✅ |
Time weighted calculations functions
Section titled “Time weighted calculations functions”time_weight() functions
| Type | Name | Toolkit | Experimental |
|---|---|---|---|
| Aggregate | time_weight() | ✅ | |
| Accessor | average() | ✅ | |
first_time() | ✅ | ||
first_val() | ✅ | ||
integral() | ✅ | ||
interpolated_average() | ✅ | ||
interpolated_integral() | ✅ | ||
last_time() | ✅ | ||
last_val() | ✅ | ||
| Rollup | rollup() | ✅ |
General functions
Section titled “General functions”| Type | Name | Toolkit | Experimental |
|---|---|---|---|
| Bucket | time_bucket() | ||
| One step aggregate | approximate_row_count() | ||
first() | |||
histogram() | |||
last() | |||
| One step operation | days_in_month() | ✅ | |
month_normalize() | ✅ |
For more information about each of the API calls listed in this table, see the hyperfunction API documentation.
Function pipelines
Section titled “Function pipelines”Function pipelines are an experimental feature, designed to radically improve the developer ergonomics of analyzing data in PostgreSQL and SQL, by applying principles from functional programming and popular tools like Python’s Pandas, and PromQL.
SQL is the best language for data analysis, but it is not perfect, and at times can get quite unwieldy. For example, this query gets data from the last day from the measurements table, sorts the data by the time column, calculates the delta between the values, takes the absolute value of the delta, and then takes the sum of the result of the previous steps:
SELECT device_id,sum(abs_delta) as volatilityFROM ( SELECT device_id,abs(val - lag(val) OVER last_day) as abs_deltaFROM measurementsWHERE ts >= now()-'1 day'::interval) calc_deltaGROUP BY device_id;You can express the same query with a function pipeline like this:
SELECT device_id, timevector(ts, val) -> sort() -> delta() -> abs() -> sum() as volatilityFROM measurementsWHERE ts >= now()-'1 day'::intervalGROUP BY device_id;Function pipelines are completely SQL compliant, meaning that any tool that speaks SQL is able to support data analysis using function pipelines.
For more information about how function pipelines work, read the blog post.
TimescaleDB Toolkit feature development
Section titled “TimescaleDB Toolkit feature development”TimescaleDB Toolkit features are developed in the open. As features are developed they are categorized as experimental, beta, stable, or deprecated. This documentation covers the stable features, but more information on experimental features in development can be found in the Toolkit repository.
Contribute to TimescaleDB Toolkit
Section titled “Contribute to TimescaleDB Toolkit”We want and need your feedback! What are the frustrating parts of analyzing time-series data? What takes far more code than you feel it should? What runs slowly, or only runs quickly after many rewrites? We want to solve community-wide problems and incorporate as much feedback as possible.
- Join the discussion.
- Check out the proposed features.
- Explore the current feature requests.
- Add your own feature request.
Learn more
Section titled “Learn more”- Gapfilling and interpolation: Fill gaps in time-series query results.
- Function pipelines: Chain hyperfunctions together for cleaner analytics queries.
- Use time buckets: SQL examples for grouping data by time intervals.
- Install TimescaleDB Toolkit: Set up the Toolkit extension for self-hosted deployments.
- Hyperfunctions API reference: Full API reference for all built-in hyperfunctions.
- TimescaleDB Toolkit API reference: Full API reference for Toolkit hyperfunctions.