mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-10-22 16:30:49 +00:00
2d2bc052e1
* Typo fix. * Links fix. * Fixed links in docs. * More fixes. * docs/en: cleaning some files * docs/en: cleaning data_types * docs/en: cleaning database_engines * docs/en: cleaning development * docs/en: cleaning getting_started * docs/en: cleaning interfaces * docs/en: cleaning operations * docs/en: cleaning query_lamguage * docs/en: cleaning en * docs/ru: cleaning data_types * docs/ru: cleaning index * docs/ru: cleaning database_engines * docs/ru: cleaning development * docs/ru: cleaning general * docs/ru: cleaning getting_started * docs/ru: cleaning interfaces * docs/ru: cleaning operations * docs/ru: cleaning query_language * docs: cleaning interfaces/http * Update docs/en/data_types/array.md decorated ``` Co-Authored-By: BayoNet <da-daos@yandex.ru> * Update docs/en/getting_started/example_datasets/nyc_taxi.md fixed typo Co-Authored-By: BayoNet <da-daos@yandex.ru> * Update docs/en/getting_started/example_datasets/ontime.md fixed typo Co-Authored-By: BayoNet <da-daos@yandex.ru> * Update docs/en/interfaces/formats.md fixed error Co-Authored-By: BayoNet <da-daos@yandex.ru> * Update docs/en/operations/table_engines/custom_partitioning_key.md Co-Authored-By: BayoNet <da-daos@yandex.ru> * Update docs/en/operations/utils/clickhouse-local.md Co-Authored-By: BayoNet <da-daos@yandex.ru> * Update docs/en/query_language/dicts/external_dicts_dict_sources.md Co-Authored-By: BayoNet <da-daos@yandex.ru> * Update docs/en/operations/utils/clickhouse-local.md Co-Authored-By: BayoNet <da-daos@yandex.ru> * Update docs/en/query_language/functions/json_functions.md Co-Authored-By: BayoNet <da-daos@yandex.ru> * Update docs/en/query_language/functions/json_functions.md Co-Authored-By: BayoNet <da-daos@yandex.ru> * Update docs/en/query_language/functions/other_functions.md Co-Authored-By: BayoNet <da-daos@yandex.ru> * Update docs/en/query_language/functions/other_functions.md Co-Authored-By: BayoNet <da-daos@yandex.ru> * Update docs/en/query_language/functions/date_time_functions.md Co-Authored-By: BayoNet <da-daos@yandex.ru> * Update docs/en/operations/table_engines/jdbc.md Co-Authored-By: BayoNet <da-daos@yandex.ru> * docs: fixed error * docs: fixed error
80 lines
3.2 KiB
Markdown
80 lines
3.2 KiB
Markdown
## IPv4
|
|
|
|
`IPv4` is a domain based on `UInt32` type and serves as typed replacement for storing IPv4 values. It provides compact storage with human-friendly input-output format, and column type information on inspection.
|
|
|
|
### Basic Usage
|
|
|
|
```sql
|
|
CREATE TABLE hits (url String, from IPv4) ENGINE = MergeTree() ORDER BY url;
|
|
|
|
DESCRIBE TABLE hits;
|
|
```
|
|
|
|
```text
|
|
┌─name─┬─type───┬─default_type─┬─default_expression─┬─comment─┬─codec_expression─┐
|
|
│ url │ String │ │ │ │ │
|
|
│ from │ IPv4 │ │ │ │ │
|
|
└──────┴────────┴──────────────┴────────────────────┴─────────┴──────────────────┘
|
|
```
|
|
|
|
OR you can use IPv4 domain as a key:
|
|
|
|
```sql
|
|
CREATE TABLE hits (url String, from IPv4) ENGINE = MergeTree() ORDER BY from;
|
|
```
|
|
|
|
`IPv4` domain supports custom input format as IPv4-strings:
|
|
|
|
```sql
|
|
INSERT INTO hits (url, from) VALUES ('https://wikipedia.org', '116.253.40.133')('https://clickhouse.yandex', '183.247.232.58')('https://clickhouse.yandex/docs/en/', '116.106.34.242');
|
|
|
|
SELECT * FROM hits;
|
|
```
|
|
|
|
```text
|
|
┌─url────────────────────────────────┬───────────from─┐
|
|
│ https://clickhouse.yandex/docs/en/ │ 116.106.34.242 │
|
|
│ https://wikipedia.org │ 116.253.40.133 │
|
|
│ https://clickhouse.yandex │ 183.247.232.58 │
|
|
└────────────────────────────────────┴────────────────┘
|
|
```
|
|
|
|
Values are stored in compact binary form:
|
|
|
|
```sql
|
|
SELECT toTypeName(from), hex(from) FROM hits LIMIT 1;
|
|
```
|
|
|
|
```text
|
|
┌─toTypeName(from)─┬─hex(from)─┐
|
|
│ IPv4 │ B7F7E83A │
|
|
└──────────────────┴───────────┘
|
|
```
|
|
|
|
Domain values are not implicitly convertible to types other than `UInt32`.
|
|
If you want to convert `IPv4` value to a string, you have to do that explicitly with `IPv4NumToString()` function:
|
|
|
|
```sql
|
|
SELECT toTypeName(s), IPv4NumToString(from) as s FROM hits LIMIT 1;
|
|
```
|
|
|
|
```
|
|
┌─toTypeName(IPv4NumToString(from))─┬─s──────────────┐
|
|
│ String │ 183.247.232.58 │
|
|
└───────────────────────────────────┴────────────────┘
|
|
```
|
|
|
|
Or cast to a `UInt32` value:
|
|
|
|
```sql
|
|
SELECT toTypeName(i), CAST(from as UInt32) as i FROM hits LIMIT 1;
|
|
```
|
|
|
|
```text
|
|
┌─toTypeName(CAST(from, 'UInt32'))─┬──────────i─┐
|
|
│ UInt32 │ 3086477370 │
|
|
└──────────────────────────────────┴────────────┘
|
|
```
|
|
|
|
[Original article](https://clickhouse.yandex/docs/en/data_types/domains/ipv4) <!--hide-->
|