dedup

Removes duplicate elements from an array.

Syntax

dedup(<array>)

Arguments

ArgumentTypeDescription
<array>arrayArray to deduplicate.

Returns

Returns array. Keeps the first occurrence of each value, including NULL, in input order. Returns NULL if the input is NULL.

Examples

Merge labels from a producer and an investigation, then retain the first occurrence of each label.

SELECT dedup(
    ['checkout', 'timeout', 'checkout'] || ['timeout', 'reviewed']
) AS labels
+-----------------------------------+
| labels                            |
+-----------------------------------+
| ["checkout","timeout","reviewed"] |
+-----------------------------------+

The result keeps the first-seen order: checkout, timeout, then reviewed.