---
title: theta_sketch_estimate function
description: Learn the syntax of the theta\_sketch\_estimate function of the SQL language in Databricks SQL and Databricks Runtime.
canonical_url: https://docs.databricks.com/aws/en/sql/language-manual/functions/theta_sketch_estimate
---

# `theta_sketch_estimate` function

**Applies to:** ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks SQL ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks Runtime 18.0 and above

Returns the estimated number of unique values from a Theta Sketch binary representation.

## Syntax

```
theta_sketch_estimate ( sketch )
```

## Arguments

* **sketch**: A Theta Sketch in binary format (such as from [`theta_sketch_agg` aggregate function](https://docs.databricks.com/aws/en/sql/language-manual/functions/theta_sketch_agg.md), [`theta_union_agg` aggregate function](https://docs.databricks.com/aws/en/sql/language-manual/functions/theta_union_agg.md), [`theta_intersection_agg` aggregate function](https://docs.databricks.com/aws/en/sql/language-manual/functions/theta_intersection_agg.md), [`theta_union` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/theta_union.md), [`theta_difference` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/theta_difference.md), or [`theta_intersection` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/theta_intersection.md)).

## Returns

A `LONG` value representing the estimated distinct count.

## Notes

* The result is rounded to the nearest integer.
* The estimate is probabilistic; accuracy depends on the `lgNomEntries` parameter used when creating the sketch.

## Common error conditions

* [THETA\_INVALID\_INPUT\_SKETCH\_BUFFER](https://docs.databricks.com/aws/en/error-messages/error-classes.md#theta_invalid_input_sketch_buffer)

## Examples

```sql
-- Get estimated distinct count from a sketch
> SELECT theta_sketch_estimate(theta_sketch_agg(col)) FROM VALUES (1), (1), (2), (2), (3) tab(col);
3
```

## Related

* [`theta_sketch_agg` aggregate function](https://docs.databricks.com/aws/en/sql/language-manual/functions/theta_sketch_agg.md)
* [`theta_union_agg` aggregate function](https://docs.databricks.com/aws/en/sql/language-manual/functions/theta_union_agg.md)
* [`theta_intersection_agg` aggregate function](https://docs.databricks.com/aws/en/sql/language-manual/functions/theta_intersection_agg.md)
