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

ARRAY_REVERSE



Reverses the order of elements in an array.

Syntax

ARRAY_REVERSE(array)

Parameters

ParameterDescription
arrayThe array to reverse.

Return Type

Array with elements in reversed order.

Notes

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

Examples

Example 1: Reversing a Standard Array

SELECT ARRAY_REVERSE([1, 2, 3, 4, 5]);

Result:

[5, 4, 3, 2, 1]

Example 2: Reversing a Variant Array

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

Result:

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

Example 3: Reversing an Empty Array

SELECT ARRAY_REVERSE([]);

Result:

[]

Was this page helpful?