Categories:

Semi-structured and 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 type of the element depends on the type of the array:

  • If array is a semi-structured ARRAY, 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.

  • If array is a structured ARRAY, the type of the new element must be coercible to the type of the ARRAY.

Returns¶

The data type of the returned value is ARRAY.

Usage Notes¶

  • When you pass a structured ARRAY to the function, the function returns a structured ARRAY of the same type.

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