

 Amazon Redshift tidak akan lagi mendukung pembuatan Python UDFs baru mulai Patch 198. Python yang ada UDFs akan terus berfungsi hingga 30 Juni 2026. Untuk informasi lebih lanjut, lihat [posting blog](https://aws.amazon.com/blogs/big-data/amazon-redshift-python-user-defined-functions-will-reach-end-of-support-after-june-30-2026/). 

Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.

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

H3\$1 ToChildren mengembalikan daftar sel H3 anak IDs pada resolusi tertentu untuk indeks H3 tertentu. Untuk informasi tentang pengindeksan H3, lihat. [H3](spatial-terminology.md#spatial-terminology-h3)

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

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

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

 *indeks*   
Nilai tipe data `BIGINT` atau `VARCHAR` yang mewakili indeks sel H3, atau ekspresi yang mengevaluasi salah satu tipe data ini.

 *resolusi*   
Nilai tipe data `INTEGER` atau ekspresi yang mengevaluasi `INTEGER` tipe. Nilai mewakili resolusi sel anak-anak IDs. Nilai harus berupa bilangan bulat antara resolusi *indeks* input dan 15, inklusif.

## Jenis pengembalian
<a name="H3_ToChildren-function-return"></a>

`SUPER`— mewakili daftar sel IDs H3.

Jika *indeks* atau *resolusi* adalah NULL, maka NULL dikembalikan.

Jika *indeks* tidak valid, maka kesalahan dikembalikan.

Jika *resolusi* tidak antara resolusi *indeks* dan 15, inklusif, maka kesalahan dikembalikan.

Jika ukuran output melebihi batas ukuran SUPER maksimum, maka kesalahan dikembalikan.

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

SQL berikut memasukkan VARCHAR yang mewakili indeks sel H3, dan INTEGER yang mewakili resolusi yang diinginkan dari semua anak, dan mengembalikan array SUPER yang berisi anak-anak pada resolusi 6.

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

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

SQL berikut memasukkan BIGINT yang mewakili indeks sel H3, dan INTEGER yang mewakili resolusi yang diinginkan dari semua anak, dan mengembalikan array SUPER yang berisi anak-anak pada resolusi 6.

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

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

Catatan: Perbedaan 7 atau kurang antara *resolusi* dan resolusi *indeks* aman.

Contoh berikut menunjukkan solusi untuk kueri yang melebihi batas ukuran SUPER. Ketika perbedaan resolusi antara indeks input H3 dan resolusi anak yang diinginkan terlalu besar (lebih besar dari 7). Prosedur ini memecahkan masalah dengan memperluas anak-anak secara bertahap dalam langkah-langkah yang lebih kecil (maksimum 5 tingkat resolusi sekaligus) dan menyimpan hasil akhir dalam tabel yang dibuat pengguna.

```
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;
```