Inet Data Type in Cassandra Query Language ( CSQL)
Inet data type in Cassandra Query Language ( CQL) is used to store IPV4 and IPV6 IP Addresses. You will be storiing the information as string. Good part of it , if you try to save the wrong IP format, it will throw an error.When I tried to insert IPV4 IP such as '10.10.10.2000' , Got below error.
InvalidRequest: Error from server: code=2200 [Invalid query] message="Unable to make inet address from '10.10.10.2000'"
Same goes for IPv6 IP type address, it validates before insert into table and if format is not correct , you will get an error as below.
InvalidRequest: Error from server: code=2200 [Invalid query] message="Unable to make inet address from '6f4e:1900:4545:3:200:f6ff:fe21:645cf'"
Let's create sample table which can store IPV4 and IPV6 type IPs in Cassandra by using Inet Data type.
CQLSH:techbrotherstutorials>CREATE TABLE tbs
(
id INT PRIMARY KEY,
ipsvalues INET
);
(
id INT PRIMARY KEY,
ipsvalues INET
);
Insert some sample data to stor IPv4 and IPV6 type IPs by using Cassandra Query Language( CQL)
CQLSH:techbrotherstutorials>INSERT INTO tbs
(
id,
ipsvalues
)
VALUES
(
1,
'10.10.10.1'
);INSERT INTO tbs
(
id,
ipsvalues
)
VALUES
(
2,
'192.168.100.21'
);INSERT INTO tbs
(
id,
ipsvalues
)
VALUES
(
3,
'4ffe:1900:3030:3:100:f7ff:fe21:67cf'
);
(
id,
ipsvalues
)
VALUES
(
1,
'10.10.10.1'
);INSERT INTO tbs
(
id,
ipsvalues
)
VALUES
(
2,
'192.168.100.21'
);INSERT INTO tbs
(
id,
ipsvalues
)
VALUES
(
3,
'4ffe:1900:3030:3:100:f7ff:fe21:67cf'
);
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.