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

> IPv6 アドレスを 16 バイトの値として格納する ClickHouse の IPv6 データ型に関するドキュメント

# IPv6

<div id="ipv6">
  ## IPv6
</div>

IPv6アドレス。16バイトのUInt128ビッグエンディアン形式で格納されます。

<div id="basic-usage">
  ### 基本的な使い方
</div>

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

DESCRIBE TABLE hits;
```

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

または、`IPv6` ドメインをキーに使用できます:

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

`IPv6` ドメインでは、IPv6文字列をカスタム入力として使用できます：

```sql theme={null}
INSERT INTO hits (url, from) VALUES ('https://wikipedia.org', '2a02:aa08:e000:3100::2')('https://clickhouse.com', '2001:44c8:129:2632:33:0:252:2')('https://clickhouse.com/docs/en/', '2a02:e980:1e::1');

SELECT * FROM hits;
```

```text theme={null}
┌─url────────────────────────────────┬─from──────────────────────────┐
│ https://clickhouse.com          │ 2001:44c8:129:2632:33:0:252:2 │
│ https://clickhouse.com/docs/en/ │ 2a02:e980:1e::1               │
│ https://wikipedia.org              │ 2a02:aa08:e000:3100::2        │
└────────────────────────────────────┴───────────────────────────────┘
```

値はコンパクトなバイナリ形式で保存されます。

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

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

IPv6アドレスはIPv4アドレスと直接比較できます。

```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 │
└─────────────────────────────────────────────────────────┘
```

**関連項目**

* [IPv4 および IPv6 アドレスの関数](/ja/reference/functions/regular-functions/ip-address-functions)
