All Products
Search
Document Center

MaxCompute:CONCAT

Last Updated:Jul 21, 2023

Concatenates all elements in multiple arrays and returns a new array, or concatenates multiple strings and returns a new string.

Syntax

array<T> concat(array<T> <a>, array<T> <b>[,...])
string concat(string <str1>, string <str2>[,...])

Parameters

  • a and b: required. These parameters specify arrays. 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 null elements are also involved in the operation.

  • str1 and str2: required. The values are of the STRING type. If the input values are of the BIGINT, DOUBLE, DECIMAL, or DATETIME type, they are implicitly converted into values of the STRING type before calculation. If the input values are of other data types, an error is returned.

Return value

  • A value of the ARRAY type is returned. If one of the input arrays is null, null is returned.

  • A value of the STRING type is returned. If no input parameters are configured or an input parameter is set to null, null is returned.

Examples

  • Example 1: Concatenate all elements of array(10, 20) and array(20, -20). Sample statement:

    -- The return value is [10, 20, 20, -20]. 
    select concat(array(10, 20), array(20, -20));
  • Example 2: One of the input arrays contains a null element. Sample statement:

    -- The return value is [10, null, 20, -20]. 
    select concat(array(10, null), array(20, -20));
  • Example 3: One of the input arrays is null. Sample statement:

    -- The return value is null. 
    select concat(array(10, 20), null);
  • Example 4: Concatenate strings aabc and abcde. Sample statement:

    -- The return value is aabcabcde. 
    select concat('aabc','abcde');
  • Example 5: The input is empty. Sample statement:

    -- The return value is null. 
    select concat();
  • Example 6: One of the input strings is null. Sample statement:

    -- The return value is null. 
    select concat('aabc', 'abcde', null);

Related functions

CONCAT is a complex type function or a string 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.

  • For more information about functions related to string searches and conversion, see String functions.