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
Language: English