All Products
Search
Document Center

MaxCompute:ARRAY_CONTAINS

Last Updated:Jul 24, 2023

Checks whether Array a contains Element v.

Syntax

boolean array_contains(array<T> <a>, value <v>)

Parameters

  • a: required. This parameter specifies an array. T in array<T> specifies the data type of the elements in the array. The elements can be of any data type.

  • v: required. This parameter specifies the element that you want to check. The value of v must be of the same data type as the elements in Array a.

Return value

A value of the BOOLEAN type is returned.

Examples

Create an array based on the data in the t_table_array table that contains the c1 (BIGINT) and t_array (ARRAY<STRING>) columns. Data in the table:

+------------+---------+
| c1         | t_array |
+------------+---------+
| 1000       | [k11, 86, k21, 15] |
| 1001       | [k12, 97, k22, 2] |
| 1002       | [k13, 99, k23, 1] |
+------------+---------+

Sample statement:

-- Check whether the t_array column contains the value 1. 
select c1, array_contains(t_array,'1') from t_table_array;
-- The following result is returned: 
+------------+------+
| c1         | _c1  |
+------------+------+
| 1000       | false |
| 1001       | false |
| 1002       | true |
+------------+------+

Related functions

ARRAY_CONTAINS 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.