적용 대상:
Databricks SQL
Databricks Runtime
element에서 처음으로 나오는 array의 위치를 반환합니다.
구문
array_position(array, element)
논쟁
-
array: 비슷한 요소가 있는 ARRAY입니다. -
element:array에 있는 요소의 형식과 일치하는 식입니다.
반품
BIGINT입니다.
배열 인덱싱은 1에서 시작합니다. 요소 값이 NULL경우 NULL 반환됩니다.
배열에서 요소를 찾을 수 없으면 0이 반환됩니다.
예제
-- 1 exists twice. The function returns the first position
> SELECT array_position(array(3, 2, 1, 4, 1), 1);
3
-- this function cannot be used to find the position of a NULL element.
> SELECT array_position(array(3, NULL, 1), NULL)
NULL
> SELECT array_position(array(3, 2, 1), NULL)
NULL
-- The element is not found in the array
> SELECT array_position(array(3, 2, 1, 4, 1), 5)
0