percentile_cont and
percentile_disc functions, making them ideal for large datasets and continuous aggregates.
TimescaleDB Toolkit provides two advanced percentile approximation algorithms:
- UddSketch: Produces stable estimates within a guaranteed relative error
- t-digest: More accurate at extreme quantiles, though somewhat dependent on input order
Two-step aggregation
This group of functions uses the two-step aggregation pattern. Rather than calculating the final result in one step, you first create an intermediate aggregate by using the aggregate function. Then, use any of the accessors on the intermediate aggregate to calculate a final result. You can also roll up multiple intermediate aggregates with the rollup functions. The two-step aggregation pattern has several advantages:- More efficient because multiple accessors can reuse the same aggregate
- Easier to reason about performance, because aggregation is separate from final computation
- Easier to understand when calculations can be rolled up into larger intervals, especially in window functions and continuous aggregates
- Perform retrospective analysis even when underlying data is dropped, because the intermediate aggregate stores extra information not available in the final result
Samples
Using percentile_agg (recommended for most use cases)
Create an hourly continuous aggregate and calculate daily percentiles:Using uddsketch for custom error control
Aggregate percentile data with specific error bounds:Using tdigest for extreme quantiles
Calculate percentiles at extreme ends of the distribution:Available functions
UddSketch (recommended)
uddsketch(): estimate percentiles using the UddSketch algorithm with guaranteed relative error
t-digest (for extreme quantiles)
tdigest(): estimate percentiles using the t-digest algorithm, optimized for extreme quantiles