Skip to content

tdigest

Provides tdigest aggregate function.

Overview

PackageVersionCategoryLicenseLanguage
tdigest1.4.7FUNCPostgreSQLC
IDExtensionBinLibLoadCreateTrustRelocSchema
4710tdigestNoYesNoYesNoYes-

Version

TypeRepoVersionPG VerPackageDeps
EXTPGDG1.4.71817161514tdigest-
RPMPGDG1.4.71817161514tdigest_$v-
DEBPGDG1.4.71817161514postgresql-$v-tdigest-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64
el8.aarch64
el9.x86_64
el9.aarch64
el10.x86_64
el10.aarch64
d12.x86_64
d12.aarch64
d13.x86_64
d13.aarch64
u22.x86_64
u22.aarch64
u24.x86_64
u24.aarch64
u26.x86_64
u26.aarch64

Install

You can install tdigest directly. First, make sure the PGDG repository is added and enabled:

pig repo add pgdg -u          # Add PGDG repo and update cache

Install the extension using pig or apt/yum/dnf:

Install
pig install tdigest;          # Install for current active PG version
pig
pig ext install -y tdigest -v 18  # PG 18
pig ext install -y tdigest -v 17  # PG 17
pig ext install -y tdigest -v 16  # PG 16
pig ext install -y tdigest -v 15  # PG 15
pig ext install -y tdigest -v 14  # PG 14
dnf
dnf install -y tdigest_18       # PG 18
dnf install -y tdigest_17       # PG 17
dnf install -y tdigest_16       # PG 16
dnf install -y tdigest_15       # PG 15
dnf install -y tdigest_14       # PG 14
apt
apt install -y postgresql-18-tdigest   # PG 18
apt install -y postgresql-17-tdigest   # PG 17
apt install -y postgresql-16-tdigest   # PG 16
apt install -y postgresql-15-tdigest   # PG 15
apt install -y postgresql-14-tdigest   # PG 14

Create Extension:

CREATE EXTENSION tdigest;

Usage

Sources:

tdigest 1.4.7 supplies approximate, mergeable rank statistics. Store partial digests and combine them to calculate quantiles without sorting the complete original data.

Core Workflow

CREATE EXTENSION tdigest;
SELECT tdigest_percentile(v, 100, ARRAY[0.5, 0.95, 0.99])
FROM generate_series(1, 1000) AS g(v);
CREATE TABLE digest_daily AS
SELECT current_date AS day, tdigest(v, 100) AS digest
FROM generate_series(1, 1000) AS g(v);
SELECT tdigest_percentile(digest, 0.95) FROM digest_daily;

Functions and Accuracy

tdigest(value, compression) builds a digest; tdigest(digest) merges stored digests. tdigest_percentile estimates quantiles and tdigest_percentile_of estimates ranks, with scalar and array forms. tdigest_add and tdigest_union update or combine digests; tdigest_count, tdigest_sum and tdigest_avg report counts and trimmed aggregates. The low and high arguments to trimmed aggregates are quantile thresholds, not raw value bounds. tdigest_is_valid checks serialized values.

compression must be between 10 and 10000. Higher values trade memory and CPU for generally better accuracy, but do not provide a fixed error bound. Validate estimates against exact results on representative data and use consistent compression when merging states.

Upgrade and Boundaries

Version 1.4.7 fixes closely spaced percentile interpolation, large-count inverse ranks, reusable-state finalization and NULL-compression handling, and marks more scalar functions parallel safe. Upgrade the installed library and SQL together with ALTER EXTENSION tdigest UPDATE TO '1.4.7'. Review stored digests with tdigest_is_valid; older malformed values can be rejected by the stricter validation. Installation requires superuser rights; the extension is relocatable and requires no preload. The release metadata sets PostgreSQL 13 as the minimum, and the changelog records PostgreSQL 19 build fixes without making a broad performance guarantee.

Was this page helpful?