topn
type for top-n JSONB
topn : type for top-n JSONB
Overview
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
| --s-d-- | No | Yes | No | Yes | no | no |
| Relationships | |
|---|---|
| See Also | 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.
Packages
| Type | Repo | Version | PG Major Compatibility | Package Pattern | Dependencies |
|---|---|---|---|---|---|
| EXT | PGDG | 2.7.1 |
18 17 16 15 14 | topn |
- |
| RPM | PGDG | 2.7.1 |
18 17 16 15 14 | topn_$v |
- |
| DEB | PIGSTY | 2.7.0 |
18 17 16 15 14 | postgresql-$v-topn |
- |
| Linux / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
| el8.x86_64 | PGDG 2.7.0 | PGDG 2.7.0 | PGDG 2.7.0 | PGDG 2.7.0 | PGDG 2.7.0 |
| el8.aarch64 | PGDG 2.7.1 | PGDG 2.7.1 | PGDG 2.7.1 | PGDG 2.7.1 | PGDG 2.7.1 |
| el9.x86_64 | PGDG 2.7.0 | PGDG 2.7.0 | PGDG 2.7.0 | PGDG 2.7.0 | PGDG 2.7.0 |
| el9.aarch64 | PGDG 2.7.1 | PGDG 2.7.1 | PGDG 2.7.1 | PGDG 2.7.1 | PGDG 2.7.1 |
| el10.x86_64 | PGDG 2.7.1 | PGDG 2.7.1 | PGDG 2.7.1 | PGDG 2.7.1 | PGDG 2.7.1 |
| el10.aarch64 | PGDG 2.7.1 | PGDG 2.7.1 | PGDG 2.7.1 | PGDG 2.7.1 | PGDG 2.7.1 |
| d12.x86_64 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 |
| d12.aarch64 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 |
| d13.x86_64 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 |
| d13.aarch64 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 |
| u22.x86_64 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 |
| u22.aarch64 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 |
| u24.x86_64 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 |
| u24.aarch64 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 |
| u26.x86_64 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 |
| u26.aarch64 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 | PIGSTY 2.7.0 |
Source
github.com/citusdata/postgresql-topn
postgresql-topn-2.7.0.tar.gz
Install
Make sure PGDG repo available:
Install this extension with pig:
Create this extension with:
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)