tdigest
Provides tdigest aggregate function.
Overview
| Package | Version | Category | License | Language |
|---|---|---|---|---|
tdigest | 1.4.4 | FUNC | Apache-2.0 | C |
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 4700 | tdigest | No | Yes | No | Yes | No | Yes | - |
| Related | ddsketch count_distinct topn omnisketch datasketches hll quantile lower_quantile weighted_statistics |
|---|
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | PGDG | 1.4.4 | 1817161514 | tdigest | - |
| RPM | PGDG | 1.4.4 | 1817161514 | tdigest_$v | - |
| DEB | PGDG | 1.4.4 | 1817161514 | postgresql-$v-tdigest | - |
Install
You can install tdigest directly. First, make sure the PGDG repository is added and enabled:
Install the extension using pig or apt/yum/dnf:
Install
pig
dnf
apt
Create Extension:
Usage
Sources:
tdigest implements an approximate, mergeable t-digest for online rank statistics such as quantiles, percentile ranks, and trimmed means. It supports parallel aggregation and storing pre-aggregated digests for later rollups.
Direct Aggregation Functions
| Function | Description |
|---|---|
tdigest_percentile(value, compression, quantile) | Estimate a single percentile |
tdigest_percentile(value, compression, quantiles[]) | Estimate multiple percentiles |
tdigest_percentile_of(value, compression, value) | Estimate percentile rank of a value |
tdigest_percentile_of(value, compression, values[]) | Estimate percentile ranks of multiple values |
Pre-aggregation Functions
| Function | Description |
|---|---|
tdigest(value, compression) | Build a t-digest from values |
tdigest_percentile(digest, quantile) | Estimate percentile from a pre-built digest |
tdigest_percentile(digest, quantiles[]) | Estimate multiple percentiles from a pre-built digest |
Incremental Update Functions
| Function | Description |
|---|---|
tdigest_add(digest, value) | Add a single value to an existing digest |
tdigest_add(digest, values[]) | Add an array of values to an existing digest |
tdigest_union(digest, digest) | Merge two digests |
Utility Functions
| Function | Description |
|---|---|
tdigest_count(digest) | Return the number of items in the digest |
tdigest_sum(digest, low, high) | Trimmed sum within a value range |
tdigest_avg(digest, low, high) | Trimmed average within a value range |
Parameters
compression– controls accuracy (higher = more accurate, larger digest). Error is roughly1/compression.
Examples
Caveats
- Results are estimates. Validate the chosen compression against exact
percentile_contresults on representative data before setting accuracy targets. - Higher compression usually improves tail accuracy but increases state size and CPU cost.
- Stored digests can be merged across groups and time windows. Version
1.4.4fixes combining digests created with different parameters, so use that patch level when heterogeneous states may meet. - Version
1.4.4also strengthens text-input parsing and validation and adds PostgreSQL 19 build/test coverage; malformed serialized digests that older builds accepted may now be rejected.
Was this page helpful?
Thanks—your feedback helps us improve this page.
What got in the way? (optional)