Categories:

Semi-structured Data Functions (Array/Object)

ARRAY_APPEND

Returns an array containing all elements from the source array as well as the new element. The new element is located at end of the array.

See also:

ARRAY_INSERT , ARRAY_PREPEND

Syntax

ARRAY_APPEND( <array> , <new_element> )

Arguments

array

The source array.

new_element

The element to be appended. The element may be of almost any data type. The data type does not need to match the data type(s) of the existing elements in the array.

Returns

The data type of the returned value is ARRAY.

Examples

This is a simple example of building an array (with the ARRAY_CONSTRUCT function) and then appending to that array. Note that the appended element does not need to be the same data type as the other elements in the array.

Execute the query:

SELECT ARRAY_APPEND(ARRAY_CONSTRUCT(1, 2, 3), 'HELLO');
+-------------------------------------------------+
| ARRAY_APPEND(ARRAY_CONSTRUCT(1, 2, 3), 'HELLO') |
|-------------------------------------------------|
| [                                               |
|   1,                                            |
|   2,                                            |
|   3,                                            |
|   "HELLO"                                       |
| ]                                               |
+-------------------------------------------------+