Returns the union of two arrays with duplicate elements removed.
Syntax
array<T> array_union(array<T> <a>, array<T> <b>)Parameters
| Parameter | Description |
|---|---|
a | Required. An array. T specifies the element data type. |
b | Required. An array of the same element type as a. |
Both arrays must have the same element data type. T supports all primitive and complex types:
Integer types: TINYINT, SMALLINT, INT, BIGINT
Floating-point types: FLOAT, DOUBLE
BOOLEAN
Exact numeric types: DECIMAL, DECIMALVAL
Date and time types: DATE, DATETIME, TIMESTAMP, IntervalDayTime, IntervalYearMonth
String and binary types: STRING, BINARY, VARCHAR, CHAR
Complex types: ARRAY, STRUCT, MAP
Return value
Returns an ARRAY containing all unique elements from both arrays. Returns null if either a or b is null.
Examples
Example 1: Return the union of two integer arrays.
SELECT array_union(array(1, 2, 3), array(1, 3, 5));
-- [1,2,3,5]Example 2: Return null when one of the arrays is null.
SELECT array_union(array(1, 2, 3), null);
-- nullRelated functions
ARRAY_UNION is a complex type function. For other functions that operate on ARRAY, MAP, STRUCT, and JSON data, see Complex type functions.