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> )
Copy

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"                                       |
| ]                                               |
+-------------------------------------------------+
Copy