ipv4
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.ac.cn', '183.247.232.58')('https://clickhouse.ac.cn/docs/en/', '116.106.34.242');
SELECT * FROM hits;
┌─url────────────────────────────────┬───────────from─┐
│ https://clickhouse.ac.cn/docs/en/ │ 116.106.34.242 │
│ https://wikipedia.org │ 116.253.40.133 │
│ https://clickhouse.ac.cn │ 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 │
└─────────────────────────────────────────────────────────┘
另请参阅