Declaration
UNIQ(expr)
Description
This function is used to approximately count the number of distinct values in a column.
Notice
This is a ClickHouse-compatible function. It is disabled by default and must be enabled by setting the sql_func_extension_mode parameter. For more information, see sql_func_extension_mode.
Examples
Enable the ClickHouse extension function mode.
obclient> ALTER SYSTEM SET sql_func_extension_mode = "ClickHouse";Create a test table named
test_tbl1.obclient> CREATE TABLE test_tbl1 (col1 INT PRIMARY KEY, col2 VARCHAR(50), col3 INT);Insert data into the
test_tbl1table.obclient> INSERT INTO test_tbl1 VALUES(1, 'a1', 6), (2, 'a2', 8), (3, 'a2', 8);Use
UNIQto count the number of distinct values in columncol3.obclient> SELECT UNIQ(col3) FROM test_tbl1;The return result is as follows:
+------------+ | UNIQ(col3) | +------------+ | 2 | +------------+ 1 row in set