All Products
Search
Document Center

MaxCompute:ARRAY_UNION

Last Updated:Jul 24, 2023

Calculates the union of Array a and Array b, and removes duplicate elements.

Syntax

array<T> array_union(array<T> <a>,  array<T> <b>)

Parameters

a and b: required. This parameter specifies an array. that T in array<T> specifies the data type of the elements in the arrays. The elements can be of any data type. The elements in Array a and the elements in Array b must be of the same data type.

The following data types are supported:

  • TINYINT, SMALLINT, INT, and BIGINT

  • FLOAT and DOUBLE

  • BOOLEAN

  • DECIMAL and DECIMALVAL

  • DATE, DATETIME, TIMESTAMP, IntervalDayTime, and IntervalYearMonth

  • STRING, BINARY, VARCHAR, and CHAR

  • ARRAY, STRUCT, and MAP

Return value

A value of the ARRAY type is returned. If Array a or Array b is null, null is returned.

Examples

  • Example 1: Calculate the union of array(1, 2, 3) and array(1, 3, 5), and remove duplicate elements. Sample statement:

    -- The return value is [1,2,3,5]. 
    select array_union(array(1, 2, 3), array(1, 3, 5));
  • Example 2: Calculate the union of two arrays and remove duplicate elements. One of the arrays is null. Sample statement:

    -- The return value is null. 
    select array_union(array(1, 2, 3), null);

Related functions

ARRAY_UNION is a complex type function. For more information about the functions that are used to process data of complex data types, such as ARRAY, MAP, STRUCT, and JSON, see Complex type functions.