1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-28 23:42:10 +03:00

Attached is a patch adding following functions:

inet(text), cidr(text): convert a text value into inet/cidr
set_masklen(inet): set masklen on the inet value

Patch also contains regression checks for these functions.

Alex Pilosov
This commit is contained in:
Bruce Momjian
2001-06-13 21:09:00 +00:00
parent 82dc79702f
commit d4a4d4c326
5 changed files with 81 additions and 3 deletions

View File

@ -18,6 +18,9 @@ INSERT INTO INET_TBL (c, i) VALUES ('10', '9.1.2.3/8');
-- check that CIDR rejects invalid input:
INSERT INTO INET_TBL (c, i) VALUES ('192.168.1.2/24', '192.168.1.226');
ERROR: invalid CIDR value '192.168.1.2/24': has bits set to right of mask
-- check that CIDR rejects invalid input when converting from text:
INSERT INTO INET_TBL (c, i) VALUES (cidr('192.168.1.2/24'), '192.168.1.226');
ERROR: invalid CIDR value '192.168.1.2/24': has bits set to right of mask
SELECT '' AS ten, c AS cidr, i AS inet FROM INET_TBL;
ten | cidr | inet
-----+----------------+------------------
@ -135,3 +138,19 @@ SELECT '' AS ten, i, c,
| 9.1.2.3/8 | 10.0.0.0/8 | t | t | f | f | f | t | f | f | f | f
(10 rows)
-- check the conversion to/from text and set_netmask
select '' AS ten, set_masklen(inet(text(i)), 24) FROM INET_TBL;
ten | set_masklen
-----+------------------
| 192.168.1.226/24
| 192.168.1.226/24
| 10.1.2.3/24
| 10.1.2.3/24
| 10.1.2.3/24
| 10.1.2.3/24
| 10.1.2.3/24
| 10.1.2.3/24
| 11.1.2.3/24
| 9.1.2.3/24
(10 rows)

View File

@ -18,6 +18,8 @@ INSERT INTO INET_TBL (c, i) VALUES ('10', '11.1.2.3/8');
INSERT INTO INET_TBL (c, i) VALUES ('10', '9.1.2.3/8');
-- check that CIDR rejects invalid input:
INSERT INTO INET_TBL (c, i) VALUES ('192.168.1.2/24', '192.168.1.226');
-- check that CIDR rejects invalid input when converting from text:
INSERT INTO INET_TBL (c, i) VALUES (cidr('192.168.1.2/24'), '192.168.1.226');
SELECT '' AS ten, c AS cidr, i AS inet FROM INET_TBL;
@ -45,3 +47,5 @@ SELECT '' AS ten, i, c,
i >> c AS sup, i >>= c AS spe
FROM INET_TBL;
-- check the conversion to/from text and set_netmask
select '' AS ten, set_masklen(inet(text(i)), 24) FROM INET_TBL;