Removes a given element from Array a.
Syntax
array<T> array_remove(array<T> <a>, T <element>)
Parameters
a: required. This parameter specifies an array.
T
inarray<T>
specifies the data type of the elements in the array. The following data types are supported:TINYINT, SMALLINT, INT, and BIGINT
FLOAT and DOUBLE
BOOLEAN
DECIMAL and DECIMALVAL
DATE, DATETIME, TIMESTAMP, IntervalDayTime, and IntervalYearMonth
STRING, BINARY, VARCHAR, and CHAR
ARRAY, STRUCT, and MAP
element: required. The element that you want to remove. The data type of this parameter must be the same as the data type of the elements in Array a.
Return value
A value of the ARRAY type is returned. The return value varies based on the following rules:
If an element in Array a is null, the null element is not involved in the operation.
If Array a or element is null, null is returned.
If Array a does not contain the specified element, Array a is returned.
Examples
Example 1: Remove
1
fromarray(3, 2, 1)
. Sample statement:-- The return value is [3,2]. select array_remove(array(3, 2, 1), 1);
Example 2: The specified element is null. Sample statement:
-- The return value is null. select array_remove(array(3, 1, null), null);
Example 3: Remove
2
fromarray(3, 1, null)
. Sample statement:-- The return value is [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.