Amazon Redshift는 패치 198부터 새 Python UDF 생성을 더 이상 지원하지 않습니다. 기존 Python UDF는 2026년 6월 30일까지 계속 작동합니다. 자세한 내용은 블로그 게시물
ARRAY_POSITIONS 함수
지정된 요소가 입력 배열에 나타나는 위치 배열(인덱스)을 반환합니다. 인덱스는 0 기반입니다. 여기서 0은 첫 번째 요소를 나타내고 1은 두 번째 요소를 나타냅니다. 요소를 찾을 수 없는 경우 빈 배열을 반환합니다.
구문
ARRAY_POSITIONS( array, value [, null_match] )
인수
- 배열
-
검색할 배열을 지정하는 SUPER 표현식입니다.
- 값
-
검색할 요소를 지정하는 값입니다.
- null_match
-
Null 값을 처리하는 방법을 지정하는 부울 값입니다.
- null_match = FALSE: Searching for NULL returns NULL. If the array contains NULL values and no match is found for a non-NULL search value, returns NULL.
- null_match = TRUE: NULLs are treated as valid, searchable elements. If the array contains NULL values and no match is found for a non-NULL search value, it returns an empty array.
기본값은 TRUE입니다.
기본 Null 처리는 구성 옵션에서도 지정할 수 있습니다.
-- same as null_match = TRUE SET default_array_search_null_handling to TRUE;
반환 타입
ARRAY_POSITIONS 함수는 SUPER 형식을 반환합니다.
예제
다음 예제에서는 ARRAY_POSITIONS 함수를 보여 줍니다.
SELECT ARRAY_POSITIONS(ARRAY('red', 'green', 'red'), 'red'); array_positions ----------------- [0,2] (1 row) SELECT ARRAY_POSITIONS(ARRAY(1, 2, 3), 4); array_positions ----------------- [] (1 row)
다음 예제에서는 null_match가 TRUE로 설정된 함수 동작을 보여 줍니다.
SET default_array_search_null_handling to TRUE; -- NULL search is enabled SELECT ARRAY_POSITIONS(ARRAY('red', NULL, 'green', NULL), NULL); array_positions ----------------- [1,3] (1 row) -- The array can contain NULLs SELECT ARRAY_POSITIONS(ARRAY('red', NULL, 'green'), 'blue', TRUE); array_positions ----------------- [] (1 row)
다음 예제에서는 null_match가 FALSE로 설정된 함수 동작을 보여 줍니다. 함수에서 null_match 동작을 지정하면 기본 구성 설정이 재정의됩니다.
-- same as null_match = TRUE SET default_array_search_null_handling to TRUE; -- NULL search is disabled. The default behavior is overridden SELECT ARRAY_POSITIONS(ARRAY('red', 'green'), NULL, FALSE); array_positions ----------------- (1 row) -- same as null_match = FALSE SET default_array_search_null_handling to FALSE; -- The array contains NULL and a match is found SELECT ARRAY_POSITIONS(ARRAY('red', NULL, 'green'), 'green'); array_positions ----------------- [2] (1 row) -- The array contains NULL but no match is found SELECT ARRAY_POSITIONS(ARRAY('red', NULL, 'green'), 'blue'); array_positions ----------------- (1 row)