Categories:

Semi-structured and 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> )
Copy

ArgumentsÂļ

array

The source array.

new_element

The element to be prepended.

ReturnsÂļ

This returns the updated array.

Usage notesÂļ

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

  • If array is a structured ARRAY, the type of the new element must be coercible to the type of the 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                                             |
| ]                                               |
+-------------------------------------------------+
Copy