About Timescale hyperfunctions

Timescale hyperfunctions are a specialized set of functions that allow you to analyze time-series data. You can use hyperfunctions to analyze anything you have stored as time-series data, including IoT devices, IT systems, marketing analytics, user behavior, financial metrics, and cryptocurrency.

Hyperfunctions allow you to perform critical time-series queries quickly, analyze time-series data, and extract meaningful information. They aim to identify, build, and combine all of the functionality SQL needs to perform time-series analysis into a single extension.

Some hyperfunctions are included in the default TimescaleDB product. For additional hyperfunctions, you need to install the Timescale Toolkit PostgreSQL extension.

Hyperfunctions available with TimescaleDB and Timescale Toolkit

Here is a list of all the hyperfunctions provided by Timescale. Hyperfunctions marked ‘Toolkit’ require an installation of Timescale Toolkit. Hyperfunctions marked ‘experimental’ 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.

Approximate count distinct functions

Hyperfunction typeHyperfunction nameToolkitExperimental
hyperloglog() functions
Aggregatehyperloglog()
Alternate aggregateapprox_count_distinct()
Accessordistinct_count()
stderror()
Rolluprollup()

Downsample functions

Hyperfunction typeHyperfunction nameToolkitExperimental
One step aggregateasap_smooth()
gp_lttb()
lttb()

Financial analysis functions

Hyperfunction typeHyperfunction nameToolkitExperimental
candlestick_agg() functions
Aggregatecandlestick_agg()
Pseudo aggregatecandlestick()
Accessorclose()
close_time()
high()
high_time()
low()
low_time()
open()
open_time()
volume()
vwap()
Rolluprollup()
ohlc() functions
Aggregateohlc()
Accessorclose()
close_time()
high()
high_time()
low()
low_time()
open()
open_time()
Rolluprollup()

Frequency analysis functions

Hyperfunction typeHyperfunction nameToolkitExperimental
count_min_sketch() functions
Aggregatecount_min_sketch()
Accessorapprox_count()
freq_agg() functions
Aggregatefreq_agg()
Accessorinto_values()
min_frequency(), max_frequency()
topn_agg() functions
Aggregatetopn_agg()
Accessorinto_values()
min_frequency(), max_frequency()
topn()

Gapfilling and interpolation functions

Hyperfunction typeHyperfunction nameToolkitExperimental
Buckettime_bucket_gapfill()
Interpolatorinterpolate()
locf()

Metric aggregation functions

Hyperfunction typeHyperfunction nameToolkitExperimental
counter_agg() functions
Aggregatecounter_agg()
Accessorcorr()
counter_zero_time()
delta()
extrapolated_delta()
extrapolated_rate()
first_time(), last_time()
first_val(), last_val()
idelta_left(), idelta_right()
intercept()
interpolated_delta()
interpolated_rate()
irate_left(), irate_right()
num_changes()
num_elements()
num_resets()
rate()
slope()
time_delta()
Rolluprollup()
Mutatorwith_bounds()
gauge_agg() functions
Aggregategauge_agg()
Accessorcorr()
delta()
extrapolated_delta()
extrapolated_rate()
idelta_left(), idelta_right()
intercept()
interpolated_delta()
interpolated_rate()
irate_left(), irate_right()
num_changes()
num_elements()
rate()
slope()
time_delta()
Rolluprollup()
Mutatorwith_bounds()

Minimum and maximum functions

Hyperfunction typeHyperfunction nameToolkitExperimental
max_n() functions
Aggregatemax_n()
Accessorinto_array()
into_values()
Rolluprollup()
max_n_by() functions
Aggregatemax_n_by()
Accessorinto_values()
Rolluprollup()
min_n() functions
Aggregatemin_n()
Accessorinto_array()
into_values()
Rolluprollup()
min_n_by() functions
Aggregatemin_n_by()
Accessorinto_values()
Rolluprollup()

Percentile approximation functions

Hyperfunction typeHyperfunction nameToolkitExperimental
tdigest() functions
Aggregatetdigest()
Accessorapprox_percentile()
approx_percentile_rank()
mean()
num_vals()
Rolluprollup()
uddsketch() functions
Aggregateuddsketch()
Accessorapprox_percentile()
approx_percentile_array()
approx_percentile_rank()
error()
mean()
num_vals()
Alternate aggregatepercentile_agg()
Rolluprollup()

Saturating math functions

Hyperfunction typeHyperfunction nameToolkitExperimental
One step operationsaturating_add()
saturating_add_pos()
saturating_mul()
saturating_sub()
saturating_sub_pos()

State aggregates functions

Hyperfunction typeHyperfunction nameToolkitExperimental
heartbeat_agg() functions
Aggregateheartbeat_agg()
Accessordead_ranges()
downtime()
interpolate()
interpolated_downtime()
interpolated_uptime()
live_at()
live_ranges()
uptime()
Rolluprollup()
state_agg() | timeline_agg() functions
Aggregatestate_agg(), timeline_agg()
Accessorduration_in()
interpolated_duration_in()
interpolated_state_periods()
interpolated_state_timeline()
into_values()
rollup()
state_periods()
state_timeline()

Statistical and regression analysis functions

Hyperfunction typeHyperfunction nameToolkitExperimental
stats_agg() (one variable) functions
Aggregatestats_agg() (one variable)
Accessorkurtosis()
num_vals()
skewness()
stddev()
sum()
variance()
average()
Rolluprolling()
rollup()
stats_agg() (two variables) functions
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 weighted calculations functions

Hyperfunction typeHyperfunction nameToolkitExperimental
time_weight() functions
Aggregatetime_weight()
Accessoraverage()
first_time()
first_val()
integral()
interpolated_average()
interpolated_integral()
last_time()
last_val()
Rolluprollup()

General functions

Hyperfunction typeHyperfunction nameToolkitExperimental
Buckettime_bucket()
timescaledb_experimental.time_bucket_ng()
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 our hyperfunction API documentation.

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:

  1. SELECT device id,
  2. sum(abs_delta) as volatility
  3. FROM (
  4. SELECT device_id,
  5. abs(val - lag(val) OVER last_day) as abs_delta
  6. FROM measurements
  7. WHERE ts >= now()-'1 day'::interval) calc_delta
  8. GROUP BY device_id;

You can express the same query with a function pipeline like this:

  1. SELECT device_id,
  2. timevector(ts, val) -> sort() -> delta() -> abs() -> sum() as volatility
  3. FROM measurements
  4. WHERE ts >= now()-'1 day'::interval
  5. 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 our blog post.

Toolkit feature development

Timescale 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 our experimental features in development can be found in the Toolkit repository.

Contribute to Timescale 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.