count_distinct
Overview
| Package | Version | Category | License | Language |
|---|---|---|---|---|
count_distinct | 3.0.2 | FUNC | BSD-2-Clause | C |
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 4630 | count_distinct | No | Yes | No | Yes | No | Yes | - |
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | PIGSTY | 3.0.2 | 1817161514 | count_distinct | - |
| RPM | PIGSTY | 3.0.2 | 1817161514 | count_distinct_$v | - |
| DEB | PIGSTY | 3.0.2 | 1817161514 | postgresql-$v-count-distinct | - |
Build
You can build the RPM / DEB packages for count_distinct using pig build:
Install
You can install count_distinct directly. First, make sure the PGDG and PIGSTY repositories are added and enabled:
Install the extension using pig or apt/yum/dnf:
Create Extension:
Usage
Sources:
Provides an alternative to COUNT(DISTINCT ...) that avoids sorting and supports parallel aggregation.
Functions
| Function | Description |
|---|---|
count_distinct(value anyelement) | Count distinct values (alternative to COUNT(DISTINCT ...)) |
array_agg_distinct(value anyelement) | Aggregate distinct values into an array |
count_distinct_elements(value anyarray) | Count distinct elements within input arrays |
array_agg_distinct_elements(value anyarray) | Aggregate distinct elements from input arrays |
Examples
Types, Memory and Version
Version 3.0.2 accepts fixed-length values passed by value, such as integers, and arrays of those values; it is not a general replacement for distinct text aggregation. Hashing a larger value first makes collisions possible and changes the result into an estimate. These aggregates keep their state in RAM and cannot reliably enforce work_mem; high cardinality or many concurrent groups can exhaust memory. Compare correctness, plans and memory use with the built-in aggregate on the actual workload rather than assuming a speedup. The control file is relocatable and has no preload requirement; C-extension installation normally needs a superuser.
Was this page helpful?
Thanks—your feedback helps us improve this page.
What got in the way? (optional)