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

> Documentação do tipo de dado IPv4 no ClickHouse

# IPv4

<div id="ipv4">
  ## IPv4
</div>

Endereços IPv4. Armazenados em 4 bytes, como UInt32.

<div id="basic-usage">
  ### Uso básico
</div>

```sql theme={null}
CREATE TABLE hits (url String, from IPv4) ENGINE = MergeTree() ORDER BY url;

DESCRIBE TABLE hits;
```

```text theme={null}
┌─name─┬─type───┬─default_type─┬─default_expression─┬─comment─┬─codec_expression─┐
│ url  │ String │              │                    │         │                  │
│ from │ IPv4   │              │                    │         │                  │
└──────┴────────┴──────────────┴────────────────────┴─────────┴──────────────────┘
```

Ou você pode usar o domínio IPv4 como chave:

```sql theme={null}
CREATE TABLE hits (url String, from IPv4) ENGINE = MergeTree() ORDER BY from;
```

O domínio `IPv4` oferece suporte a um formato de entrada personalizado na forma de strings IPv4:

```sql theme={null}
INSERT INTO hits (url, from) VALUES ('https://wikipedia.org', '116.253.40.133')('https://clickhouse.com', '183.247.232.58')('https://clickhouse.com/docs/en/', '116.106.34.242');

SELECT * FROM hits;
```

```text theme={null}
┌─url────────────────────────────────┬───────────from─┐
│ https://clickhouse.com/docs/en/ │ 116.106.34.242 │
│ https://wikipedia.org              │ 116.253.40.133 │
│ https://clickhouse.com          │ 183.247.232.58 │
└────────────────────────────────────┴────────────────┘
```

Os valores são armazenados em forma binária compacta:

```sql theme={null}
SELECT toTypeName(from), hex(from) FROM hits LIMIT 1;
```

```text theme={null}
┌─toTypeName(from)─┬─hex(from)─┐
│ IPv4             │ B7F7E83A  │
└──────────────────┴───────────┘
```

Endereços IPv4 podem ser comparados diretamente com endereços IPv6:

```sql theme={null}
SELECT toIPv4('127.0.0.1') = toIPv6('::ffff:127.0.0.1');
```

```text theme={null}
┌─equals(toIPv4('127.0.0.1'), toIPv6('::ffff:127.0.0.1'))─┐
│                                                       1 │
└─────────────────────────────────────────────────────────┘
```

**Veja também**

* [Funções para trabalhar com endereços IPv4 e IPv6](/pt-BR/reference/functions/regular-functions/ip-address-functions)
