Skip to content

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.

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.

Warning

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.

Tips

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.

TypeNameToolkitExperimental
Aggregatehyperloglog()
Alternate aggregateapprox_count_distinct()
Accessordistinct_count()
stderror()
Rolluprollup()

counter_agg() functions

TypeNameToolkitExperimental
Aggregatecounter_agg()
Accessorcorr()
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()
Rolluprollup()
Mutatorwith_bounds()

gauge_agg() functions

TypeNameToolkitExperimental
Aggregategauge_agg()
Accessorcorr()
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()
Rolluprollup()
Mutatorwith_bounds()
TypeNameToolkitExperimental
Functionasap_smooth()
lttb()
gp_lttb()

candlestick_agg() functions

TypeNameToolkitExperimental
Aggregatecandlestick_agg()
Pseudo aggregatecandlestick()
Accessorclose()
close_time()
high()
high_time()
low()
low_time()
open()
open_time()
volume()
vwap()
Rolluprollup()

count_min_sketch() functions

TypeNameToolkitExperimental
Aggregatecount_min_sketch()
Accessorapprox_count()

freq_agg() functions

TypeNameToolkitExperimental
Aggregatefreq_agg()
Accessorinto_values()
max_frequency()
min_frequency()
topn()
Alternate aggregatemcv_agg()
Rolluprollup()
TypeNameToolkitExperimental
Buckettime_bucket_gapfill()
Interpolatorinterpolate()
locf()

max_n() functions

TypeNameToolkitExperimental
Aggregatemax_n()
Accessorinto_values()
into_array()
Rolluprollup()

max_n_by() functions

TypeNameToolkitExperimental
Aggregatemax_n_by()
Accessorinto_values()
Rolluprollup()

min_n() functions

TypeNameToolkitExperimental
Aggregatemin_n()
Accessorinto_array()
into_values()
Rolluprollup()

min_n_by() functions

TypeNameToolkitExperimental
Aggregatemin_n_by()
Accessorinto_values()
Rolluprollup()

tdigest() functions

TypeNameToolkitExperimental
Aggregatetdigest()
Accessorapprox_percentile()
approx_percentile_rank()
mean()
num_vals()
Rolluprollup()

percentile_agg() / uddsketch() functions

TypeNameToolkitExperimental
Aggregatepercentile_agg()
Alternate aggregateuddsketch()
Accessorapprox_percentile()
approx_percentile_rank()
error()
mean()
num_vals()
Rolluprollup()
TypeNameToolkitExperimental
Functionsaturating_add()
saturating_add_pos()
saturating_mul()
saturating_sub()
saturating_sub_pos()

compact_state_agg() functions

TypeNameToolkitExperimental
Aggregatecompact_state_agg()
Accessorduration_in()
interpolated_duration_in()
into_values()
Rolluprollup()

heartbeat_agg() functions

TypeNameToolkitExperimental
Aggregateheartbeat_agg()
Accessordead_ranges()
downtime()
interpolate()
interpolated_downtime()
interpolated_uptime()
live_ranges()
num_gaps()
live_at()
num_live_ranges()
trim_to()
uptime()
Rolluprollup()

state_agg() functions

TypeNameToolkitExperimental
Aggregatestate_agg()
Accessorduration_in()
interpolated_duration_in()
interpolated_state_periods()
interpolated_state_timeline()
into_values()
state_at()
state_periods()
state_timeline()
Rolluprollup()

Statistical and regression analysis functions

Section titled “Statistical and regression analysis functions”

stats_agg() (one variable) functions

TypeNameToolkitExperimental
Aggregatestats_agg() (one variable)
Accessoraverage()
num_vals()
kurtosis()
skewness()
stddev()
sum()
variance()
Rolluprolling()
rollup()

stats_agg() (two variables) functions

TypeNameToolkitExperimental
Aggregatestats_agg() (two variables)
Accessoraverage_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()
Rolluprolling()
rollup()

time_weight() functions

TypeNameToolkitExperimental
Aggregatetime_weight()
Accessoraverage()
first_time()
first_val()
integral()
interpolated_average()
interpolated_integral()
last_time()
last_val()
Rolluprollup()
TypeNameToolkitExperimental
Buckettime_bucket()
One step aggregateapproximate_row_count()
first()
histogram()
last()
One step operationdays_in_month()
month_normalize()

For more information about each of the API calls listed in this table, see the hyperfunction API documentation.

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 volatility
FROM (
SELECT device_id,
abs(val - lag(val) OVER last_day) as abs_delta
FROM measurements
WHERE ts >= now()-'1 day'::interval) calc_delta
GROUP 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 volatility
FROM measurements
WHERE ts >= now()-'1 day'::interval
GROUP 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 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.

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.