Skip to main content
Since 1.0.0 Aggregate data in a UddSketch, using reasonable default values, for further calculation of percentile estimates. This is an alternate first step for calculating approximate percentiles. It provides added convenience by using sensible defaults to create a UddSketch. Internally, it calls uddsketch with 200 buckets and a maximum error rate of 0.001. Use percentile_agg to create an intermediate aggregate from your raw data. This intermediate form can then be used by one or more accessors in this group to compute final results. Optionally, multiple such intermediate aggregate objects can be combined using rollup() before an accessor is applied.
percentile_agg(
  value DOUBLE PRECISION
) RETURNS UddSketch

Arguments

NameTypeDefaultRequiredDescription
valueDOUBLE PRECISION-column of values to aggregate for percentile calculation

Returns

ColumnTypeDescription
percentile_aggUddSketcha percentile estimator object created to calculate percentiles using the UddSketch algorithm

Samples

Create a continuous aggregate that stores percentile aggregate objects. These objects can later be used with multiple accessors for retrospective analysis.
CREATE MATERIALIZED VIEW foo_hourly
WITH (timescaledb.continuous)
AS SELECT
    time_bucket('1 h'::interval, ts) as bucket,
    percentile_agg(value) as pct_agg
FROM foo
GROUP BY 1;