Concatenates multiple arrays into a new array, or concatenates multiple strings into a new string.
Array overload: Returns null if any input array is null. Null elements within an array are included in the result.
String overload: Returns null if any input parameter is null or if no parameters are provided.
Syntax
array<T> concat(array<T> <a>, array<T> <b>[,...])
string concat(string <str1>, string <str2>[,...])Parameters
Array overload
| Parameter | Required | Type | Description |
|---|---|---|---|
a, b | Yes | ARRAY | Arrays to concatenate. All arrays must contain elements of the same data type. T can be any data type. Null elements are included in the result. |
String overload
| Parameter | Required | Type | Description |
|---|---|---|---|
str1, str2 | Yes | STRING | Strings to concatenate. BIGINT, DOUBLE, DECIMAL, and DATETIME values are implicitly converted to STRING before concatenation. Other data types cause an error. |
Return value
Array overload: Returns an ARRAY value. Returns null if any input array is null.
String overload: Returns a STRING value. Returns null if no parameters are provided, or if any parameter is null.
Examples
Array concatenation
-- Returns: [10, 20, 20, -20]
select concat(array(10, 20), array(20, -20));-- Null elements are included in the result. Returns: [10, null, 20, -20]
select concat(array(10, null), array(20, -20));-- A null array causes the function to return null. Returns: null
select concat(array(10, 20), null);String concatenation
-- Returns: aabcabcde
select concat('aabc', 'abcde');-- No parameters. Returns: null
select concat();-- A null string parameter causes the function to return null. Returns: null
select concat('aabc', 'abcde', null);Related functions
CONCAT is available as both a complex type function and a string function.
For functions that process ARRAY, MAP, STRUCT, and JSON data, see Complex type functions.
For functions related to string search and conversion, see String functions.