云数据库 GAUSSDB-网络地址类型:cidr

时间:2024-11-02 18:50:28

cidr

cidr(无类别域间路由,Classless Inter-Domain Routing)类型,保存一个IPv4网络地址。声明网络格式为address/y,address表示IPv4地址,y表示子网掩码的二进制位数。如果省略y,则掩码部分使用已有类别的网络编号系统进行计算,但要求输入的数据已经包括了确定掩码所需的所有字节。具体请参见表2

表2 cidr类型输入举例

cidr输入

cidr输出

abbrev(cidr)

192.168.100.128/25

192.168.100.128/25

192.168.100.128/25

192.168/24

192.168.0.0/24

192.168.0/24

192.168/25

192.168.0.0/25

192.168.0.0/25

192.168.1

192.168.1.0/24

192.168.1/24

192.168

192.168.0.0/24

192.168.0/24

10.1.2

10.1.2.0/24

10.1.2/24

10.1

10.1.0.0/16

10.1/16

10

10.0.0.0/8

10/8

10.1.2.3/32

10.1.2.3/32

10.1.2.3/32

示例:

gaussdb=# CREATE TABLE cidr_test(id int, c cidr);
CREATE TABLE
gaussdb=# INSERT INTO cidr_test VALUES (1, '192.168.100.128/25');
INSERT 0 1
gaussdb=# INSERT INTO cidr_test VALUES (2, '192.168/24');
INSERT 0 1
gaussdb=# INSERT INTO cidr_test VALUES (3, '192.168/25');
INSERT 0 1
gaussdb=# INSERT INTO cidr_test VALUES (4, '192.168.1');
INSERT 0 1
gaussdb=# INSERT INTO cidr_test VALUES (5, '192.168');
INSERT 0 1
gaussdb=# INSERT INTO cidr_test VALUES (6, '10.1.2');
INSERT 0 1
gaussdb=# INSERT INTO cidr_test VALUES (7, '10.1');
INSERT 0 1
gaussdb=# INSERT INTO cidr_test VALUES (8, '10');
INSERT 0 1
gaussdb=# INSERT INTO cidr_test VALUES (9, '2001:4f8:3:ba::/64');
INSERT 0 1
gaussdb=# INSERT INTO cidr_test VALUES (10, '2001:4f8:3:ba:2e0:81ff:fe22:d1f1/128');
INSERT 0 1
gaussdb=# INSERT INTO cidr_test VALUES (11, '::ffff:127.0.0.0/120');
INSERT 0 1
gaussdb=# INSERT INTO cidr_test VALUES (12, '::ffff:127.0.0.0/128');
INSERT 0 1
gaussdb=# SELECT * FROM cidr_test ORDER BY id;
 id |                  c                   
----+--------------------------------------
  1 | 192.168.100.128/25
  2 | 192.168.0.0/24
  3 | 192.168.0.0/25
  4 | 192.168.1.0/24
  5 | 192.168.0.0/24
  6 | 10.1.2.0/24
  7 | 10.1.0.0/16
  8 | 10.0.0.0/8
  9 | 2001:4f8:3:ba::/64
 10 | 2001:4f8:3:ba:2e0:81ff:fe22:d1f1/128
 11 | ::ffff:127.0.0.0/120
 12 | ::ffff:127.0.0.0/128
(12 rows)

gaussdb=# DROP TABLE cidr_test;
DROP TABLE
support.huaweicloud.com/centralized-devg-v3-gaussdb/gaussdb-12-0320.html