> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify-poc.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# approx_count_distinct()

> Aggregate data into a hyperloglog for approximate counting without specifying the number of buckets

<Icon icon="tag" iconType="duotone" /> Since [1.16.0][toolkit-1.16.0]

This is an alternate first step for approximating the number of distinct
values. It provides some added convenience by using some sensible default
parameters to create a `hyperloglog`.

Use `approx_count_distinct` to create an intermediate aggregate from your raw data.
This intermediate form can then be used by one or more accessors in this
group to compute final results.

Optionally, multiple such intermediate aggregate objects can be combined
using [`rollup()`][rollup] before an accessor is applied.

## Samples

Given a table called `samples`, with a column called `weights`, return
a `hyperloglog` over the `weights` column:

```sql theme={"dark"}
SELECT approx_count_distinct(weights) FROM samples;
```

Using the same data, build a view from the aggregate that you can pass
to other `hyperloglog` functions.

```sql theme={"dark"}
CREATE VIEW hll AS SELECT approx_count_distinct(data) FROM samples;
```

## Arguments

The syntax is:

```sql theme={"dark"}
approx_count_distinct(
    value AnyElement
) RETURNS Hyperloglog
```

| Name    | Type       | Default | Required | Description                                                                                         |
| ------- | ---------- | ------- | -------- | --------------------------------------------------------------------------------------------------- |
| `value` | AnyElement | -       | ✔        | The column containing the elements to count. The type must have an extended, 64-bit, hash function. |

## Returns

| Column      | Type        | Description                                                                                            |
| ----------- | ----------- | ------------------------------------------------------------------------------------------------------ |
| hyperloglog | Hyperloglog | A `hyperloglog` object which can be passed to other hyperloglog APIs for rollups and final calculation |

[rollup]: /api-reference/timescaledb-toolkit/hyperloglog/rollup

[toolkit-1.16.0]: https://github.com/timescale/timescaledb-toolkit/releases/tag/1.16.0
