Skip to main content

array_concat, ||

Returns a concatenation of two arrays.

The || operator provides alternative syntax for ARRAY_CONCAT and can concatenate more than two arrays.

Syntax

array_concat( <array1> , <array2> )

Arguments

<array1>

The source array.

<array2>

The array to be appended to <array1>.

Returns

An ARRAY containing the elements from <array2> appended after the elements of <array1>.

If any input value is NULL, returns NULL.

Examples

This example shows how to use array_concat:

VALUES ([1, 2], [3, 4])
SELECT array_concat([1, 2], [3, 4]);
+------------------------------+
| array_concat([1, 2], [3, 4]) |
+------------------------------+
| [1,2,3,4] |
+------------------------------+

Use the || concatenation operator instead of the function:

SELECT [1, 2, 3] || [] || ["other", "solutions"];
+-------------------------------------------+
| [1, 2, 3] || [] || ['other', 'solutions'] |
+-------------------------------------------+
| [1,2,3,'other','solutions'] |
+-------------------------------------------+