Link Search Menu Expand Document

APPROX_COUNT_DISTINCT

Counts the approximate number of unique or not NULL values. APPROX_COUNT_DISTINCT uses the HLL algorithm with the default parameter to control the sketch size set to 17. This is subject to change.

Syntax

APPROX_COUNT_DISTINCT ( <expression> )

Parameters

Parameter Description Supported input types
<expression> Expression that the APPROX_COUNT_DISTANCE function is applied to Any <column> name or any function that returns a <column> name

By default, APPROX_COUNT_DISTINCT and COUNT(DISTINCT) return the same, approximate results. If you require a precise result for COUNT(DISTINCT) (with a performance penalty), please contact Firebolt Support through the Help menu support form.

Return Type

INTEGER

Example

The following example draws from the INTEGER column playerid from the players table. The code calculates the COUNT of playerid values as well as the APPROX_COUNT_DISTINCT of these two values in a labeled table:

SELECT
	COUNT(DISTINCT playerid) as playerid_count_distinct,
	APPROX_COUNT_DISTINCT(playerid) as playerid_approx_count
FROM
	players;

Returns:

playerid_count_distinct playerid_approx_count
5,420 5,428