IPv4 데이터 타입
IPv4 데이터 타입
IPv4 주소를 저장하는 데이터 타입이에요. 4바이트(UInt32)로 저장돼요.
출처: 문서
본문
IPv4
IPv4 주소예요. UInt32로 4바이트에 저장돼요.
기본 사용 (Basic Usage)
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 │
└─────────────────────────────────────────────────────────┘