Functions for Working with Embedded Dictionaries

### regionToDistrict[​](#regiontodistrict "Direct link to regionToDistrict")

Converts a region to a federal district (type 4 in the geobase). In every other way, this function is the same as 'regionToCity'.

**Syntax**

```
regionToDistrict(id [, geobase])
```

**Parameters**

- `id` — Region ID from the geobase. [UInt32](/docs/sql-reference/data-types/int-uint).
- `geobase` — Dictionary key. See [Multiple Geobases](#multiple-geobases). [String](/docs/sql-reference/data-types/string). Optional.

**Returned value**

- Region ID for the appropriate city, if it exists. [UInt32](/docs/sql-reference/data-types/int-uint).
- 0, if there is none.

**Example**

Query:

```
SELECT DISTINCT regionToName(regionToDistrict(toUInt32(number), 'ua'))
FROM system.numbers
LIMIT 15
```

Result:

```
┌─regionToName(regionToDistrict(toUInt32(number), \'ua\'))─┐
│                                                          │
│ Central federal district                                 │
│ Northwest federal district                               │
│ South federal district                                   │
│ North Caucases federal district                          │
│ Privolga federal district                                │
│ Ural federal district                                    │
│ Siberian federal district                                │
│ Far East federal district                                │
│ Scotland                                                 │
│ Faroe Islands                                            │
│ Flemish region                                           │
│ Brussels capital region                                  │
│ Wallonia                                                 │
│ Federation of Bosnia and Herzegovina                     │
└──────────────────────────────────────────────────────────┘
```

### regionToCountry[​](#regiontocountry "Direct link to regionToCountry")

Converts a region to a country (type 3 in the geobase). In every other way, this function is the same as 'regionToCity'.

**Syntax**

```
regionToCountry(id [, geobase])
```

**Parameters**

- `id` — Region ID from the geobase. [UInt32](/docs/sql-reference/data-types/int-uint).
- `geobase` — Dictionary key. See [Multiple Geobases](#multiple-geobases). [String](/docs/sql-reference/data-types/string). Optional.

**Returned value**

- Region ID for the appropriate country, if it exists. [UInt32](/docs/sql-reference/data-types/int-uint).
- 0, if there is none.

**Example**

Query:

```
SELECT regionToName(number::UInt32, 'en'), regionToCountry(number::UInt32) AS id, regionToName(id, 'en') FROM numbers(13);
```

Result:

```
┌─regionToName(CAST(number, 'UInt32'), 'en')─┬─id─┬─regionToName(regionToCountry(CAST(number, 'UInt32')), 'en')─┐
│                                            │  0 │                                                             │
│ World                                      │  0 │                                                             │
│ USA                                        │  2 │ USA                                                         │
│ Colorado                                   │  2 │ USA                                                         │
│ Boulder County                             │  2 │ USA                                                         │
│ Boulder                                    │  2 │ USA                                                         │
│ China                                      │  6 │ China                                                       │
│ Sichuan                                    │  6 │ China                                                       │
│ Chengdu                                    │  6 │ China                                                       │
│ America                                    │  0 │                                                             │
│ North America                              │  0 │                                                             │
│ Eurasia                                    │  0 │                                                             │
│ Asia                                       │  0 │                                                             │
└────────────────────────────────────────────┴────┴─────────────────────────────────────────────────────────────┘
```

### regionToContinent[​](#regiontocontinent "Direct link to regionToContinent")

Converts a region to a continent (type 1 in the geobase). In every other way, this function is the same as 'regionToCity'.

**Syntax**

```
regionToContinent(id [, geobase])
```

**Parameters**

- `id` — Region ID from the geobase. [UInt32](/docs/sql-reference/data-types/int-uint).
- `geobase` — Dictionary key. See [Multiple Geobases](#multiple-geobases). [String](/docs/sql-reference/data-types/string). Optional.

**Returned value**

- Region ID for the appropriate continent, if it exists. [UInt32](/docs/sql-reference/data-types/int-uint).
- 0, if there is none.

**Example**

Query:

```
SELECT regionToName(number::UInt32, 'en'), regionToContinent(number::UInt32) AS id, regionToName(id, 'en') FROM numbers(13);
```

Result:

```
┌─regionToName(CAST(number, 'UInt32'), 'en')─┬─id─┬─regionToName(regionToContinent(CAST(number, 'UInt32')), 'en')─┐
│                                            │  0 │                                                               │
│ World                                      │  0 │                                                               │
│ USA                                        │ 10 │ North America                                                 │
│ Colorado                                   │ 10 │ North America                                                 │
│ Boulder County                             │ 10 │ North America                                                 │
│ Boulder                                    │ 10 │ North America                                                 │
│ China                                      │ 12 │ Asia                                                          │
│ Sichuan                                    │ 12 │ Asia                                                          │
│ Chengdu                                    │ 12 │ Asia                                                          │
│ America                                    │  9 │ America                                                       │
│ North America                              │ 10 │ North America                                                 │
│ Eurasia                                    │ 11 │ Eurasia                                                       │
│ Asia                                       │ 12 │ Asia                                                          │
└────────────────────────────────────────────┴────┴───────────────────────────────────────────────────────────────┘
```

### regionToTopContinent[​](#regiontotopcontinent "Direct link to regionToTopContinent")

Finds the highest continent in the hierarchy for the region.

**Syntax**

```
regionToTopContinent(id[, geobase])
```

**Parameters**

- `id` — Region ID from the geobase. [UInt32](/docs/sql-reference/data-types/int-uint).
- `geobase` — Dictionary key. See [Multiple Geobases](#multiple-geobases). [String](/docs/sql-reference/data-types/string). Optional.

**Returned value**

- Identifier of the top level continent (the latter when you climb the hierarchy of regions).[UInt32](/docs/sql-reference/data-types/int-uint).
- 0, if there is none.

**Example**

Query:

```
SELECT regionToName(number::UInt32, 'en'), regionToTopContinent(number::UInt32) AS id, regionToName(id, 'en') FROM numbers(13);
```

Result: