Skip to main content
Validates that a column or expression has no duplicate values. Use it for primary keys, natural keys, and any value that should identify a single row. This is a SQL data test: Elementary runs it against your warehouse on a schedule, with no SQL to write and no pull request.
SQL-based cloud tests read table data, so they need data access for the environment’s warehouse connection. Data access is enabled in one of two ways:
  • Elementary enables data access on the warehouse connection. Contact the Elementary team to turn it on.
  • You connect an Elementary Runtime to the warehouse connection.
Until data access is available, these tests are hidden from the test catalog.

How it works

On each run, Elementary groups the table by the tested value and returns every value that appears more than once, together with the number of times it appears.
  • Failing rows are duplicated values. If the value 1042 appears in three rows, it counts as one failing row with a duplicate count of 3.
  • Nulls are ignored. Rows where the value is null are never counted as duplicates. To require a value in every row, add a completeness test.
  • The where clause applies before grouping. Only rows that match the condition are compared with each other.
Results count toward the Uniqueness data quality dimension.

Configuration

Severity, thresholds, sampled rows, and cadence work the same for all SQL data tests. See Configuration.

Examples

Example result

The sample lists each duplicated value and its count: The failing-row count for this result is 2: two values are duplicated.

dbt equivalent

The dbt unique test checks the same rule from your dbt project. For a combination of columns, use an expression here, or dbt_utils.unique_combination_of_columns in dbt. See Cloud tests or dbt tests to decide which to use.