> ## 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.

> Documentación del tipo de datos IPv4 en ClickHouse

# IPv4

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

Direcciones IPv4. Se almacenan en 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   │              │                    │         │                  │
└──────┴────────┴──────────────┴────────────────────┴─────────┴──────────────────┘
```

O bien, puedes usar el dominio IPv4 como clave:

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

El dominio `IPv4` admite un formato de entrada personalizado con cadenas 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 │
└────────────────────────────────────┴────────────────┘
```

Los valores se almacenan en formato binario compacto:

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

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

Las direcciones IPv4 pueden compararse directamente con las direcciones 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 │
└─────────────────────────────────────────────────────────┘
```

**Consulte también**

* [Funciones para trabajar con direcciones IPv4 e IPv6](/es/reference/functions/regular-functions/ip-address-functions)
