

 Amazon Redshift는 패치 198부터 새 Python UDF 생성을 더 이상 지원하지 않습니다. 기존 Python UDF는 2026년 6월 30일까지 계속 작동합니다. 자세한 내용은 [블로그 게시물](https://aws.amazon.com/blogs/big-data/amazon-redshift-python-user-defined-functions-will-reach-end-of-support-after-june-30-2026/)을 참조하세요.

# H3\$1ToChildren
<a name="H3_ToChildren-function"></a>

H3\$1ToChildren은 주어진 H3 인덱스에 대해 지정된 해상도로 하위 H3 셀 ID 목록을 반환합니다. H3 인덱싱에 대한 자세한 내용은 [H3](spatial-terminology.md#spatial-terminology-h3) 섹션을 참조하세요.

## 구문
<a name="H3_ToChildren-function-syntax"></a>

```
H3_ToChildren(index, resolution)
```

## 인수
<a name="H3_ToChildren-function-arguments"></a>

 * 인덱스*   
H3 셀의 인덱스를 나타내는 `BIGINT` 또는 `VARCHAR` 데이터 유형의 값이나 이러한 데이터 유형으로 평가되는 표현식입니다.

 *resolution*   
`INTEGER` 데이터 유형의 값 또는 `INTEGER` 유형으로 계산되는 식입니다. 값은 하위 셀 ID의 해상도를 나타냅니다. 값은 입력 *인덱스*의 해상도와 15 사이의 정수여야 합니다.

## 반환 타입
<a name="H3_ToChildren-function-return"></a>

`SUPER` - H3 셀 ID 목록을 나타냅니다.

*인덱스* 또는 *해상도*가 NULL이면 NULL이 반환됩니다.

*index*가 유효하지 않으면 오류가 반환됩니다.

*인덱스*의 해상도와 15 사이의 *해상도*가 아닌 경우 오류가 반환됩니다.

출력 크기가 최대 SUPER 크기 제한을 초과하면 오류가 반환됩니다.

## 예제
<a name="H3_ToChildren-function-examples"></a>

다음 SQL은 H3 셀의 인덱스를 나타내는 VARCHAR와 모든 하위 요소의 원하는 해상도를 나타내는 INTEGER를 입력하고 해상도 6에서 하위 요소가 포함된 SUPER 배열을 반환합니다.

```
SELECT H3_ToChildren('85283473fffffff', 6);
```

```
 h3_tochildren                                                
--------------------------------------------------------------------------------------------------------------------------------------
 [604189641121202175,604189641255419903,604189641389637631,604189641523855359,604189641658073087,604189641792290815,604189641926508543]
```

다음 SQL은 H3 셀의 인덱스를 나타내는 BIGINT와 모든 하위 요소의 원하는 해상도를 나타내는 INTEGER를 입력하고 해상도 6에서 하위 요소가 포함된 SUPER 배열을 반환합니다.

```
SELECT H3_ToChildren(599686042433355775, 6);
```

```
 h3_tochildren                                              
--------------------------------------------------------------------------------------------------------------------------------------
 [604189641121202175,604189641255419903,604189641389637631,604189641523855359,604189641658073087,604189641792290815,604189641926508543]
```

참고: *해상도*와 *인덱스* 해상도의 차이가 7 이하이면 안전합니다.

다음 예제에서는 SUPER 크기 제한을 초과하는 쿼리에 대한 해결 방법을 보여줍니다. 입력 H3 인덱스와 원하는 하위 해상도 간의 해상도 차이가 너무 큰 경우(7 초과). 이 절차에서는 하위 항목을 더 작은 단계(한 번에 최대 5개 해상도)로 점진적으로 확장하고 최종 결과를 사용자 생성 테이블에 저장하여 문제를 해결합니다.

```
CREATE OR REPLACE PROCEDURE generate_h3_children()
LANGUAGE plpgsql
AS $$
BEGIN
    -- Drop and create h3_children table that will contain the results
    DROP TABLE IF EXISTS h3_children;
    CREATE TABLE h3_children (
        h3_index BIGINT,
        child_res INTEGER,
        children SUPER
    );

    -- Create temporary table for steps
    DROP TABLE IF EXISTS h3_steps;
    CREATE TABLE h3_steps (
        h3_index BIGINT,
        current_res INTEGER,
        target_res INTEGER,
        h3_array SUPER
    );

    -- Initial insert into h3_steps
    INSERT INTO h3_steps
    SELECT h3_index, H3_Resolution(h3_index), child_res, ARRAY(h3_index)
    FROM h3_indexes; -- Insert from your table with h3_index and child_res as columns

    -- Loop until we reach target resolution
    -- We expect at most 3 iterations considering that we can start at resolution
    -- 0 and target/child resolution equal to 15 (0 -> 5 -> 10 -> 15)
    WHILE EXISTS (
        SELECT 1
        FROM h3_steps h
        GROUP BY h3_index, target_res
        HAVING MAX(current_res) < target_res
    ) LOOP
        -- Populate the h3_steps table with the tables that need to
        -- reach closer to the target res
        INSERT INTO h3_steps
        SELECT
            h.h3_index,
            LEAST(h.current_res + 5, h.target_res), -- Do not exceed target res
            h.target_res,
            -- Take the children of the child cell at resolution current_res of the
            -- h3_index
            H3_ToChildren(c.child::BIGINT, LEAST(h.current_res + 5, h.target_res))
        FROM h3_steps h, UNNEST(h.h3_array) AS c(child)
        WHERE h.current_res < h.target_res
        AND h.current_res = (SELECT MAX(current_res)
                           FROM h3_steps
                           WHERE h3_index = h.h3_index
        );
    END LOOP;

    -- Store final results
    INSERT INTO h3_children
    SELECT h3_index AS h3_index, target_res AS child_res, h3_array AS children
    FROM h3_steps
    WHERE current_res = target_res;
END;
$$;

-- Create the source table for H3_ToChildren queries
CREATE TABLE h3_indexes (
    h3_index BIGINT,
    child_res INTEGER,
    PRIMARY KEY (h3_index, child_res)
);
INSERT INTO h3_indexes (h3_index, child_res)
VALUES (x'8001fffffffffff'::BIGINT, 11);

-- Execute the procedure
CALL generate_h3_children();

-- View results
SELECT * FROM h3_children;
```