dataengref migrate

Home / Redshift

Redshift APPROXIMATE COUNT(DISTINCT) in Snowflake, Databricks and BigQuery

Redshift writes the approximate distinct count as a keyword in front of COUNT. The targets use a function instead: APPROX_COUNT_DISTINCT in all three.

Redshift syntax: APPROXIMATE COUNT(DISTINCT expression) · Redshift docs

Equivalents

TargetSupportSyntaxNotesSource
SnowflakeRewriteAPPROX_COUNT_DISTINCT(expr)HyperLogLog estimate.Snowflake docs
DatabricksRewriteapprox_count_distinct(expr [, relativeSD])relativeSD sets the allowed relative error.Databricks docs
BigQueryRewriteAPPROX_COUNT_DISTINCT(expression)HyperLogLog++ estimate.BigQuery docs

Behavior differences to check

Examples

Approximate daily active users

Redshift
SELECT event_date, APPROXIMATE COUNT(DISTINCT user_id) AS dau FROM events GROUP BY event_date;
Snowflake
SELECT event_date, APPROX_COUNT_DISTINCT(user_id) AS dau FROM events GROUP BY event_date;
Databricks
SELECT event_date, approx_count_distinct(user_id) AS dau FROM events GROUP BY event_date;
BigQuery
SELECT event_date, APPROX_COUNT_DISTINCT(user_id) AS dau FROM events GROUP BY event_date;

Other Redshift functions

Last checked: · Paste a whole query into the SQL checker to find every function that needs a change.