Skip to main content
Skip to main content

uniqExact

Calculates the exact number of different argument values.

uniqExact(x[, ...])

Use the uniqExact function if you absolutely need an exact result. Otherwise use the uniq function.

The uniqExact function uses more memory than uniq, because the size of the state has unbounded growth as the number of different values increases.

Arguments

The function takes a variable number of parameters. Parameters can be Tuple, Array, Date, DateTime, String, or numeric types.

Example

In this example we'll use the uniqExact function to count the number of unique type codes (a short identifier for the type of aircraft) in the opensky data set.

SELECT uniqExact(typecode) FROM opensky.opensky
1106

See Also

uniqExact

Introduced in: v1.1

Calculates the exact number of different argument values.

Note

The uniqExact function uses more memory than uniq, because the size of the state has unbounded growth as the number of different values increases. Use the uniqExact function if you absolutely need an exact result. Otherwise use the uniq function.

Syntax

uniqExact(x[, ...])

Arguments

Returned value

Returns the exact number of different argument values as a UInt64. UInt64

Examples

Basic usage

CREATE TABLE example_data
(
    id UInt32,
    category String
)
ENGINE = Memory;

INSERT INTO example_data VALUES
(1, 'A'), (2, 'B'), (3, 'A'), (4, 'C'), (5, 'B'), (6, 'A');

SELECT uniqExact(category) as exact_unique_categories
FROM example_data;
┌─exact_unique_categories─┐
│                       3 │
└─────────────────────────┘

Multiple arguments

SELECT uniqExact(id, category) as exact_unique_combinations
FROM example_data;
┌─exact_unique_combinations─┐
│                         6 │
└───────────────────────────┘