IPv4
IPv4 地址。以 4 字节的 UInt32 存储。
基本用法
CREATE TABLE hits (url String, from IPv4) ENGINE = MergeTree() ORDER BY url;
DESCRIBE TABLE hits;┌─name─┬─type───┬─default_type─┬─default_expression─┬─comment─┬─codec_expression─┐
│ url │ String │ │ │ │ │
│ from │ IPv4 │ │ │ │ │
└──────┴────────┴──────────────┴────────────────────┴─────────┴──────────────────┘或者,也可以使用 IPv4 域作为键:
CREATE TABLE hits (url String, from IPv4) ENGINE = MergeTree() ORDER BY from;IPv4 域支持将 IPv4 字符串用作自定义输入格式:
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;┌─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 │
└────────────────────────────────────┴────────────────┘值以紧凑的二进制格式存储:
SELECT toTypeName(from), hex(from) FROM hits LIMIT 1;┌─toTypeName(from)─┬─hex(from)─┐
│ IPv4 │ B7F7E83A │
└──────────────────┴───────────┘IPv4 地址可以直接与 IPv6 地址进行比较:
SELECT toIPv4('127.0.0.1') = toIPv6('::ffff:127.0.0.1');┌─equals(toIPv4('127.0.0.1'), toIPv6('::ffff:127.0.0.1'))─┐
│ 1 │
└─────────────────────────────────────────────────────────┘另请参阅