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

ARRAY_REMOVE_FIRST



Removes the first occurrence of an element from an array.

Syntax

ARRAY_REMOVE_FIRST(array, element)

Parameters

ParameterDescription
arrayThe source array from which to remove the element.
elementThe element to remove from the array.

Return Type

Array with the first occurrence of the specified element removed.

Notes

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

Examples

Example 1: Removing from a Standard Array

SELECT ARRAY_REMOVE_FIRST([1, 2, 2, 3], 2);

Result:

[1, 2, 3]

Example 2: Removing from a Variant Array

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

Result:

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

Example 3: Element Not Found

SELECT ARRAY_REMOVE_FIRST([1, 2, 3], 4);

Result:

[1, 2, 3]

Was this page helpful?