topn
type for top-n JSONB
Repository
citusdata/postgresql-topn
https://github.com/citusdata/postgresql-topn
Source
postgresql-topn-2.7.0.tar.gz
postgresql-topn-2.7.0.tar.gz
Overview
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 4600 | topn | No | Yes | No | Yes | No | No | - |
| Related | count_distinct hll omnisketch datasketches ddsketch tdigest quantile lower_quantile weighted_statistics |
|---|
Latest PGDG RPM/catalog version is 2.7.1; EL8/EL9 x86_64, Pigsty DEB, and Pigsty source remain on 2.7.0.
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | PGDG | 2.7.1 | 1817161514 | topn | - |
| RPM | PGDG | 2.7.1 | 1817161514 | topn_$v | - |
| DEB | PIGSTY | 2.7.0 | 1817161514 | postgresql-$v-topn | - |
Build
You can build the DEB packages for topn using pig build:
Install
You can install topn 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
Provides approximate top-N value tracking using an approximation algorithm that keeps a predefined number of frequent items and counters. Supports materialization, incremental updates, and merging across time intervals.
Data Type
Uses JSONB to store the frequent items and their frequencies.
Aggregates
| Function | Description |
|---|---|
topn_add_agg(text) | Aggregate that creates a JSONB counter from a text column |
topn_union_agg(jsonb) | Aggregate that merges multiple JSONB counter lists |
Functions
| Function | Description |
|---|---|
topn(jsonb, n) | Return the top-N elements and frequencies as rows |
topn_add(jsonb, text) | Add a text value to a JSONB counter |
topn_union(jsonb, jsonb) | Merge two JSONB counter lists |
Configuration
topn.number_of_counters– number of counters to track (default: 1000)
Examples
Was this page helpful?
Thanks—your feedback helps us improve this page.
What got in the way? (optional)