Categories:

Semi-structured Data Functions (Array/Object)

ARRAY_PREPEND

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

See also:

ARRAY_APPEND , ARRAY_INSERT

Syntax

ARRAY_PREPEND( <array> , <new_element> )

Arguments

array

The source array.

new_element

The element to be prepended.

Returns

This returns the updated array.

Examples

The example below shows that the prepended element is placed at the beginning of the array:

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