Skip to main content

ARRAY_REMOVE_FIRST

Introduced or updated: v1.2.762

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]
Try Databend Cloud for FREE

Multimodal, object-storage-native warehouse for BI, vectors, search, and geo.

Snowflake-compatible SQL with automatic scaling.

Sign up and get $200 in credits.

Try it today