📣
TiDB Cloud Premium is now in public preview. Unlimited growth, instant elasticity, advanced security for enterprise workloads. Try it out →

ARRAY_PREPEND



Prepends an element to the beginning of an array.

Syntax

ARRAY_PREPEND(element, array)

Parameters

ParameterDescription
elementThe element to prepend to the array.
arrayThe source array to which the element will be prepended.

Return Type

Array with the prepended element.

Notes

This function works with both standard array types and variant array types.

Examples

Example 1: Prepending to a Standard Array

SELECT ARRAY_PREPEND(0, [1, 2, 3]);

Result:

[0, 1, 2, 3]

Example 2: Prepending to a Variant Array

SELECT ARRAY_PREPEND('apple', PARSE_JSON('["banana", "orange"]'));

Result:

["apple", "banana", "orange"]

Example 3: Prepending a Complex Element

SELECT ARRAY_PREPEND(PARSE_JSON('{"value": 0}'), [1, 2, 3]);

Result:

[{"value": 0}, 1, 2, 3]

Was this page helpful?