> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-fix-nav-issues.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Hierarchical dictionaries

> Configure hierarchical dictionaries with parent-child key relationships.

<h2 id="hierarchical-dictionaries">
  Hierarchical dictionaries
</h2>

ClickHouse supports hierarchical dictionaries with a [numeric key](/reference/statements/create/dictionary/attributes#numeric-key).

Look at the following hierarchical structure:

```text theme={null}
0 (Common parent)
│
├── 1 (United States of America)
│   │
│   └── 2 (California)
│       │
│       └── 3 (San Francisco)
│
└── 4 (Great Britain)
    │
    └── 5 (London)
```

This hierarchy can be expressed as the following dictionary table.

| region\_id | parent\_region | region\_name             |
| ---------- | -------------- | ------------------------ |
| 1          | 0              | United States of America |
| 2          | 1              | California               |
| 3          | 2              | San Francisco            |
| 4          | 0              | Great Britain            |
| 5          | 4              | London                   |

This table contains a column `parent_region` that contains the key of the nearest parent for the element.

ClickHouse supports the hierarchical property for external dictionary attributes. This property allows you to configure the hierarchical dictionary similar to what is described above.

The [dictGetHierarchy](/reference/functions/regular-functions/ext-dict-functions#dictGetHierarchy) function allows you to get the parent chain of an element.

For our example, the structure of the dictionary can be the following:

<Tabs>
  <Tab title="DDL">
    ```sql theme={null}
    CREATE DICTIONARY regions_dict
    (
        region_id UInt64,
        parent_region UInt64 DEFAULT 0 HIERARCHICAL,
        region_name String DEFAULT ''
    )
    PRIMARY KEY region_id
    SOURCE(...)
    LAYOUT(HASHED())
    LIFETIME(3600);
    ```
  </Tab>

  <Tab title="Configuration file">
    ```xml theme={null}
    <dictionary>
        <structure>
            <id>
                <name>region_id</name>
            </id>

            <attribute>
                <name>parent_region</name>
                <type>UInt64</type>
                <null_value>0</null_value>
                <hierarchical>true</hierarchical>
            </attribute>

            <attribute>
                <name>region_name</name>
                <type>String</type>
                <null_value></null_value>
            </attribute>

        </structure>
    </dictionary>
    ```
  </Tab>
</Tabs>

<br />
