quantile

Quantile aggregation function

Overview

PackageVersionCategoryLicenseLanguage
quantile1.1.8FUNCBSD 2-ClauseC
IDExtensionBinLibLoadCreateTrustRelocSchema
4610quantileNoYesNoYesNoNo-
Relatedlower_quantile topn ddsketch omnisketch count_distinct first_last_agg aggs_for_arrays

Version

TypeRepoVersionPG VerPackageDeps
EXTPIGSTY1.1.81817161514quantile-
RPMPIGSTY1.1.81817161514quantile_$v-
DEBPIGSTY1.1.81817161514postgresql-$v-quantile-
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
PIGSTY 1.1.8
PIGSTY 1.1.8
PIGSTY 1.1.8
PIGSTY 1.1.8
PIGSTY 1.1.8
u22.x86_64
PIGSTY 1.1.8
PIGSTY 1.1.8
PIGSTY 1.1.8
PIGSTY 1.1.8
PIGSTY 1.1.8
u22.aarch64
PIGSTY 1.1.8
PIGSTY 1.1.8
PIGSTY 1.1.8
PIGSTY 1.1.8
PIGSTY 1.1.8
u24.x86_64
PIGSTY 1.1.8
PIGSTY 1.1.8
PIGSTY 1.1.8
PIGSTY 1.1.8
PIGSTY 1.1.8
u24.aarch64
PIGSTY 1.1.8
PIGSTY 1.1.8
PIGSTY 1.1.8
PIGSTY 1.1.8
PIGSTY 1.1.8

Build

You can build the RPM / DEB packages for quantile using pig build:

pig build pkg quantile         # build RPM / DEB packages

Install

You can install quantile directly. First, make sure the PGDG and PIGSTY repositories are added and enabled:

pig repo add pgsql -u          # Add repo and update cache

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

pig install quantile;          # Install for current active PG version
pig ext install -y quantile -v 18  # PG 18
pig ext install -y quantile -v 17  # PG 17
pig ext install -y quantile -v 16  # PG 16
pig ext install -y quantile -v 15  # PG 15
pig ext install -y quantile -v 14  # PG 14
dnf install -y quantile_18       # PG 18
dnf install -y quantile_17       # PG 17
dnf install -y quantile_16       # PG 16
dnf install -y quantile_15       # PG 15
dnf install -y quantile_14       # PG 14
apt install -y postgresql-18-quantile   # PG 18
apt install -y postgresql-17-quantile   # PG 17
apt install -y postgresql-16-quantile   # PG 16
apt install -y postgresql-15-quantile   # PG 15
apt install -y postgresql-14-quantile   # PG 14

Create Extension:

CREATE EXTENSION quantile;

Usage

quantile: quantile aggregate functions for PostgreSQL

Provides aggregate functions to compute quantiles. Overloaded for int, bigint, double precision, and numeric.

CREATE EXTENSION quantile;

Functions

FunctionDescription
quantile(value, quantile float)Compute a single quantile (0 to 1)
quantile(value, quantiles float[])Compute multiple quantiles at once, returns array

Examples

-- Compute the median (0.5 quantile)
SELECT quantile(i, 0.5) FROM generate_series(1, 1000) s(i);
-- 500

-- Compute the 95th percentile
SELECT quantile(i, 0.95) FROM generate_series(1, 1000) s(i);

-- Compute all quartiles at once (more efficient than separate calls)
SELECT quantile(i, ARRAY[0.25, 0.5, 0.75])
FROM generate_series(1, 1000) s(i);
-- {250, 500, 750}

Note: Since PostgreSQL 9.4, built-in percentile_cont and percentile_disc functions are available. Consider using those first and only use this extension if it provides measurably better performance for your workload.


Last Modified 2026-03-12: add pg extension catalog (95749bf)