tdigest
Provides tdigest aggregate function.
tdigest : Provides tdigest aggregate function.
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 4700 | tdigest | tdigest | 1.4.4 |
FUNC | Apache-2.0 | C |
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
| --s-d-r | No | Yes | No | Yes | yes | no |
| Relationships | |
|---|---|
| See Also | ddsketch count_distinct topn omnisketch datasketches hll quantile lower_quantile weighted_statistics |
Packages
| Type | Repo | Version | PG Major Compatibility | Package Pattern | Dependencies |
|---|---|---|---|---|---|
| EXT | PGDG | 1.4.4 |
18 17 16 15 14 | tdigest |
- |
| RPM | PGDG | 1.4.4 |
18 17 16 15 14 | tdigest_$v |
- |
| DEB | PGDG | 1.4.4 |
18 17 16 15 14 | postgresql-$v-tdigest |
- |
| Linux / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
| el8.x86_64 | PGDG 1.4.4 | PGDG 1.4.4 | PGDG 1.4.4 | PGDG 1.4.4 | PGDG 1.4.4 |
| el8.aarch64 | PGDG 1.4.4 | PGDG 1.4.4 | PGDG 1.4.4 | PGDG 1.4.4 | PGDG 1.4.4 |
| el9.x86_64 | PGDG 1.4.4 | PGDG 1.4.4 | PGDG 1.4.4 | PGDG 1.4.4 | PGDG 1.4.4 |
| el9.aarch64 | PGDG 1.4.4 | PGDG 1.4.4 | PGDG 1.4.4 | PGDG 1.4.4 | PGDG 1.4.4 |
| el10.x86_64 | PGDG 1.4.4 | PGDG 1.4.4 | PGDG 1.4.4 | PGDG 1.4.4 | PGDG 1.4.4 |
| el10.aarch64 | PGDG 1.4.4 | PGDG 1.4.4 | PGDG 1.4.4 | PGDG 1.4.4 | PGDG 1.4.4 |
| d12.x86_64 | PGDG 1.4.4 | PGDG 1.4.4 | PGDG 1.4.4 | PGDG 1.4.4 | PGDG 1.4.4 |
| d12.aarch64 | PGDG 1.4.4 | PGDG 1.4.4 | PGDG 1.4.4 | PGDG 1.4.4 | PGDG 1.4.4 |
| d13.x86_64 | PGDG 1.4.4 | PGDG 1.4.4 | PGDG 1.4.4 | PGDG 1.4.4 | PGDG 1.4.4 |
| d13.aarch64 | PGDG 1.4.4 | PGDG 1.4.4 | PGDG 1.4.4 | PGDG 1.4.4 | PGDG 1.4.4 |
| u22.x86_64 | PGDG 1.4.4 | PGDG 1.4.4 | PGDG 1.4.4 | PGDG 1.4.4 | PGDG 1.4.4 |
| u22.aarch64 | PGDG 1.4.4 | PGDG 1.4.4 | PGDG 1.4.4 | PGDG 1.4.4 | PGDG 1.4.4 |
| u24.x86_64 | PGDG 1.4.4 | PGDG 1.4.4 | PGDG 1.4.4 | PGDG 1.4.4 | PGDG 1.4.4 |
| u24.aarch64 | PGDG 1.4.4 | PGDG 1.4.4 | PGDG 1.4.4 | PGDG 1.4.4 | PGDG 1.4.4 |
| u26.x86_64 | PGDG 1.4.4 | PGDG 1.4.4 | PGDG 1.4.4 | PGDG 1.4.4 | PGDG 1.4.4 |
| u26.aarch64 | PGDG 1.4.4 | PGDG 1.4.4 | PGDG 1.4.4 | PGDG 1.4.4 | PGDG 1.4.4 |
Source
github.com/tvondra/tdigest
Install
Make sure PGDG repo available:
Install this extension with pig:
Create this extension with:
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.