Removes a given element from Array a. For example, array_remove(array(3, 2, 1), 1) returns [3, 2].
Syntax
array<T> array_remove(array<T> <a>, T <element>)
Parameters
-
a: Required. The source array.
Tinarray<T>is the element data type. Supported types:-
TINYINT, SMALLINT, INT, BIGINT
-
FLOAT, DOUBLE
-
BOOLEAN
-
DECIMAL, DECIMALVAL
-
DATE, DATETIME, TIMESTAMP, IntervalDayTime, IntervalYearMonth
-
STRING, BINARY, VARCHAR, CHAR
-
ARRAY, STRUCT, MAP
-
-
element: Required. The value to remove. The data type must match that of the elements in
a.
Return value
Returns an ARRAY value.
Usage notes
-
If
aorelementis null, the function returns null. -
Null elements in
aare skipped during comparison and preserved in the output. -
If
adoes not containelement, the function returnsaunchanged.
Examples
The following examples cover standard removal, a null element argument, and an element not present in the array.
-- Remove 1 from array(3, 2, 1). Returns [3,2].
select array_remove(array(3, 2, 1), 1);
-- Pass null as the element to remove. Returns null.
select array_remove(array(3, 1, null), null);
-- Remove 2 from array(3, 1, null), where 2 is not present. Returns [3,1,null].
select array_remove(array(3, 1, null), 2);
Related functions
ARRAY_REMOVE is a complex type function. For more information about the functions that are used to process data of complex data types, such as ARRAY, MAP, STRUCT, and JSON, see Complex type functions.