Largest Triangle Three Buckets is a downsampling method that tries to retain visual similarity between the downsampled data and the original dataset. The TimescaleDB Toolkit implementation of this takes (timestamp, value) pairs, sorts them if needed, and downsamples them.

Required arguments

timeTIMESTAMPTZTime (x) value for the data point
valueDOUBLE PRECISIONData (y) value for the data point
resolutionINTEGERNumber of points the output should have


sortedtimevectorSortedTimevectorA timevector object containing the downsampled points. It can be unpacked via unnest.

Sample usage

This example creates a dramatically downsampled data set from a sample_data table:

SELECT time, value
FROM toolkit_experimental.unnest((
    SELECT toolkit_experimental.lttb(time, val, 4)
    FROM sample_data))

The output for this query:

time          |       value
 2020-01-11 00:00:00+00 |   12.7015115293407
 2020-02-01 00:00:00+00 |  5.004324248633603
 2020-03-03 00:00:00+00 | 14.982710485116087
 2020-04-20 00:00:00+00 | 10.022128489940254

Found an issue on this page?

Report an issue!

Related Content