- About Timescale hyperfunctions
- Approximate count distinct functions
- Downsample functions
- Financial analysis functions
- Frequency analysis functions
- Gapfilling and interpolation functions
- Metric aggregation functions
- Minimum and maximum functions
- Percentile approximation functions
- Saturating math functions
- State aggregates functions
- Statistical and regression analysis functions
- Time weighted calculations functions
- General functions
- Function pipelines
- Toolkit feature development
- Contribute to Timescale Toolkit
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 type | Hyperfunction name | Toolkit | Experimental | |
---|---|---|---|---|
hyperloglog() functions | ||||
Aggregate | hyperloglog() | ✅ | ||
Alternate aggregate | approx_count_distinct() | ✅ | ✅ | |
Accessor | distinct_count() | ✅ | ||
stderror() | ✅ | |||
Rollup | rollup() | ✅ |
Downsample functions
Hyperfunction type | Hyperfunction name | Toolkit | Experimental |
---|---|---|---|
One step aggregate | asap_smooth() | ✅ | |
gp_lttb() | ✅ | ✅ | |
lttb() | ✅ |
Financial analysis functions
Hyperfunction type | Hyperfunction name | Toolkit | Experimental | |
---|---|---|---|---|
candlestick_agg() functions | ||||
Aggregate | candlestick_agg() | ✅ | ✅ | |
Pseudo aggregate | candlestick() | ✅ | ✅ | |
Accessor | close() | ✅ | ✅ | |
close_time() | ✅ | ✅ | ||
high() | ✅ | ✅ | ||
high_time() | ✅ | ✅ | ||
low() | ✅ | ✅ | ||
low_time() | ✅ | ✅ | ||
open() | ✅ | ✅ | ||
open_time() | ✅ | ✅ | ||
volume() | ✅ | ✅ | ||
vwap() | ✅ | ✅ | ||
Rollup | rollup() | ✅ | ✅ | |
ohlc() functions | ||||
Aggregate | ohlc() | ✅ | ✅ | |
Accessor | close() | ✅ | ✅ | |
close_time() | ✅ | ✅ | ||
high() | ✅ | ✅ | ||
high_time() | ✅ | ✅ | ||
low() | ✅ | ✅ | ||
low_time() | ✅ | ✅ | ||
open() | ✅ | ✅ | ||
open_time() | ✅ | ✅ | ||
Rollup | rollup() | ✅ | ✅ |
Frequency analysis functions
Hyperfunction type | Hyperfunction name | Toolkit | Experimental | |
---|---|---|---|---|
count_min_sketch() functions | ||||
Aggregate | count_min_sketch() | ✅ | ✅ | |
Accessor | approx_count() | ✅ | ✅ | |
freq_agg() functions | ||||
Aggregate | freq_agg() | ✅ | ✅ | |
Accessor | into_values() | ✅ | ✅ | |
min_frequency(), max_frequency() | ✅ | ✅ | ||
topn_agg() functions | ||||
Aggregate | topn_agg() | ✅ | ✅ | |
Accessor | into_values() | ✅ | ✅ | |
min_frequency(), max_frequency() | ✅ | ✅ | ||
topn() | ✅ | ✅ |
Gapfilling and interpolation functions
Hyperfunction type | Hyperfunction name | Toolkit | Experimental |
---|---|---|---|
Bucket | time_bucket_gapfill() | ||
Interpolator | interpolate() | ||
locf() |
Metric aggregation functions
Hyperfunction type | Hyperfunction name | Toolkit | Experimental | |
---|---|---|---|---|
counter_agg() functions | ||||
Aggregate | counter_agg() | ✅ | ||
Accessor | corr() | ✅ | ||
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() | ✅ | |||
Rollup | rollup() | ✅ | ||
Mutator | with_bounds() | ✅ | ||
gauge_agg() functions | ||||
Aggregate | gauge_agg() | ✅ | ✅ | |
Accessor | corr() | ✅ | ||
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() | ✅ | |||
Rollup | rollup() | ✅ | ||
Mutator | with_bounds() | ✅ |
Minimum and maximum functions
Hyperfunction type | Hyperfunction name | Toolkit | Experimental | |
---|---|---|---|---|
max_n() functions | ||||
Aggregate | max_n() | ✅ | ✅ | |
Accessor | into_array() | ✅ | ✅ | |
into_values() | ✅ | ✅ | ||
Rollup | rollup() | ✅ | ✅ | |
max_n_by() functions | ||||
Aggregate | max_n_by() | ✅ | ✅ | |
Accessor | into_values() | ✅ | ✅ | |
Rollup | rollup() | ✅ | ✅ | |
min_n() functions | ||||
Aggregate | min_n() | ✅ | ✅ | |
Accessor | into_array() | ✅ | ✅ | |
into_values() | ✅ | ✅ | ||
Rollup | rollup() | ✅ | ✅ | |
min_n_by() functions | ||||
Aggregate | min_n_by() | ✅ | ✅ | |
Accessor | into_values() | ✅ | ✅ | |
Rollup | rollup() | ✅ | ✅ |
Percentile approximation functions
Hyperfunction type | Hyperfunction name | Toolkit | Experimental | |
---|---|---|---|---|
tdigest() functions | ||||
Aggregate | tdigest() | ✅ | ||
Accessor | approx_percentile() | ✅ | ||
approx_percentile_rank() | ✅ | |||
mean() | ✅ | |||
num_vals() | ✅ | |||
Rollup | rollup() | ✅ | ||
uddsketch() functions | ||||
Aggregate | uddsketch() | ✅ | ||
Accessor | approx_percentile() | ✅ | ||
approx_percentile_array() | ✅ | ✅ | ||
approx_percentile_rank() | ✅ | |||
error() | ✅ | |||
mean() | ✅ | |||
num_vals() | ✅ | |||
Alternate aggregate | percentile_agg() | ✅ | ||
Rollup | rollup() | ✅ |
Saturating math functions
Hyperfunction type | Hyperfunction name | Toolkit | Experimental |
---|---|---|---|
One step operation | saturating_add() | ✅ | ✅ |
saturating_add_pos() | ✅ | ✅ | |
saturating_mul() | ✅ | ✅ | |
saturating_sub() | ✅ | ✅ | |
saturating_sub_pos() | ✅ | ✅ |
State aggregates functions
Hyperfunction type | Hyperfunction name | Toolkit | Experimental | |
---|---|---|---|---|
heartbeat_agg() functions | ||||
Aggregate | heartbeat_agg() | ✅ | ✅ | |
Accessor | dead_ranges() | ✅ | ✅ | |
downtime() | ✅ | ✅ | ||
interpolate() | ✅ | ✅ | ||
interpolated_downtime() | ✅ | ✅ | ||
interpolated_uptime() | ✅ | ✅ | ||
live_at() | ✅ | ✅ | ||
live_ranges() | ✅ | ✅ | ||
uptime() | ✅ | ✅ | ||
Rollup | rollup() | ✅ | ✅ | |
state_agg() | timeline_agg() functions | ||||
Aggregate | state_agg(), timeline_agg() | ✅ | ✅ | |
Accessor | duration_in() | ✅ | ✅ | |
interpolated_duration_in() | ✅ | ✅ | ||
interpolated_state_periods() | ✅ | ✅ | ||
interpolated_state_timeline() | ✅ | ✅ | ||
into_values() | ✅ | ✅ | ||
rollup() | ✅ | ✅ | ||
state_periods() | ✅ | ✅ | ||
state_timeline() | ✅ | ✅ |
Statistical and regression analysis functions
Hyperfunction type | Hyperfunction name | Toolkit | Experimental | |
---|---|---|---|---|
stats_agg() (one variable) functions | ||||
Aggregate | stats_agg() (one variable) | ✅ | ||
Accessor | kurtosis() | ✅ | ||
num_vals() | ✅ | |||
skewness() | ✅ | |||
stddev() | ✅ | |||
sum() | ✅ | |||
variance() | ✅ | |||
average() | ✅ | |||
Rollup | rolling() | ✅ | ||
rollup() | ✅ | |||
stats_agg() (two variables) functions | ||||
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
Hyperfunction type | Hyperfunction name | Toolkit | Experimental | |
---|---|---|---|---|
time_weight() functions | ||||
Aggregate | time_weight() | ✅ | ||
Accessor | average() | ✅ | ||
first_time() | ✅ | |||
first_val() | ✅ | |||
integral() | ✅ | ✅ | ||
interpolated_average() | ✅ | ✅ | ||
interpolated_integral() | ✅ | ✅ | ||
last_time() | ✅ | |||
last_val() | ✅ | |||
Rollup | rollup() | ✅ |
General functions
Hyperfunction type | Hyperfunction name | Toolkit | Experimental |
---|---|---|---|
Bucket | time_bucket() | ||
timescaledb_experimental.time_bucket_ng() | ✅ | ||
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 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:
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 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.
- Join the discussion.
- Check out the proposed features.
- Explore the current feature requests.
- Add your own feature request.