1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-09 22:41:56 +03:00

Change default output formatting for CIDR to be unabbreviated, per

recommendation from Paul Vixie.  Add a new abbrev() function to produce
abbreviated format as text.  No forced initdb, but new function is not
available unless you do an initdb or add the pg_proc row manually.
This commit is contained in:
Tom Lane
2000-12-22 18:00:24 +00:00
parent 13b78a2400
commit 61784c54b5
6 changed files with 151 additions and 91 deletions

View File

@ -19,18 +19,18 @@ INSERT INTO INET_TBL (c, i) VALUES ('10', '9.1.2.3/8');
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
SELECT '' AS ten, c AS cidr, i AS inet FROM INET_TBL;
ten | cidr | inet
-----+--------------+------------------
| 192.168.1/24 | 192.168.1.226/24
| 192.168.1/24 | 192.168.1.226
| 10/8 | 10.1.2.3/8
| 10.0.0.0/32 | 10.1.2.3/8
| 10.1.2.3/32 | 10.1.2.3
| 10.1.2/24 | 10.1.2.3/24
| 10.1/16 | 10.1.2.3/16
| 10/8 | 10.1.2.3/8
| 10/8 | 11.1.2.3/8
| 10/8 | 9.1.2.3/8
ten | cidr | inet
-----+----------------+------------------
| 192.168.1.0/24 | 192.168.1.226/24
| 192.168.1.0/24 | 192.168.1.226
| 10.0.0.0/8 | 10.1.2.3/8
| 10.0.0.0/32 | 10.1.2.3/8
| 10.1.2.3/32 | 10.1.2.3
| 10.1.2.0/24 | 10.1.2.3/24
| 10.1.0.0/16 | 10.1.2.3/16
| 10.0.0.0/8 | 10.1.2.3/8
| 10.0.0.0/8 | 11.1.2.3/8
| 10.0.0.0/8 | 9.1.2.3/8
(10 rows)
-- now test some support functions
@ -51,61 +51,61 @@ SELECT '' AS ten, i AS inet, host(i), text(i) FROM INET_TBL;
SELECT '' AS ten, c AS cidr, broadcast(c),
i AS inet, broadcast(i) FROM INET_TBL;
ten | cidr | broadcast | inet | broadcast
-----+--------------+------------------+------------------+------------------
| 192.168.1/24 | 192.168.1.255/24 | 192.168.1.226/24 | 192.168.1.255/24
| 192.168.1/24 | 192.168.1.255/24 | 192.168.1.226 | 192.168.1.226
| 10/8 | 10.255.255.255/8 | 10.1.2.3/8 | 10.255.255.255/8
| 10.0.0.0/32 | 10.0.0.0 | 10.1.2.3/8 | 10.255.255.255/8
| 10.1.2.3/32 | 10.1.2.3 | 10.1.2.3 | 10.1.2.3
| 10.1.2/24 | 10.1.2.255/24 | 10.1.2.3/24 | 10.1.2.255/24
| 10.1/16 | 10.1.255.255/16 | 10.1.2.3/16 | 10.1.255.255/16
| 10/8 | 10.255.255.255/8 | 10.1.2.3/8 | 10.255.255.255/8
| 10/8 | 10.255.255.255/8 | 11.1.2.3/8 | 11.255.255.255/8
| 10/8 | 10.255.255.255/8 | 9.1.2.3/8 | 9.255.255.255/8
ten | cidr | broadcast | inet | broadcast
-----+----------------+------------------+------------------+------------------
| 192.168.1.0/24 | 192.168.1.255/24 | 192.168.1.226/24 | 192.168.1.255/24
| 192.168.1.0/24 | 192.168.1.255/24 | 192.168.1.226 | 192.168.1.226
| 10.0.0.0/8 | 10.255.255.255/8 | 10.1.2.3/8 | 10.255.255.255/8
| 10.0.0.0/32 | 10.0.0.0 | 10.1.2.3/8 | 10.255.255.255/8
| 10.1.2.3/32 | 10.1.2.3 | 10.1.2.3 | 10.1.2.3
| 10.1.2.0/24 | 10.1.2.255/24 | 10.1.2.3/24 | 10.1.2.255/24
| 10.1.0.0/16 | 10.1.255.255/16 | 10.1.2.3/16 | 10.1.255.255/16
| 10.0.0.0/8 | 10.255.255.255/8 | 10.1.2.3/8 | 10.255.255.255/8
| 10.0.0.0/8 | 10.255.255.255/8 | 11.1.2.3/8 | 11.255.255.255/8
| 10.0.0.0/8 | 10.255.255.255/8 | 9.1.2.3/8 | 9.255.255.255/8
(10 rows)
SELECT '' AS ten, c AS cidr, network(c) AS "network(cidr)",
i AS inet, network(i) AS "network(inet)" FROM INET_TBL;
ten | cidr | network(cidr) | inet | network(inet)
-----+--------------+---------------+------------------+------------------
| 192.168.1/24 | 192.168.1/24 | 192.168.1.226/24 | 192.168.1/24
| 192.168.1/24 | 192.168.1/24 | 192.168.1.226 | 192.168.1.226/32
| 10/8 | 10/8 | 10.1.2.3/8 | 10/8
| 10.0.0.0/32 | 10.0.0.0/32 | 10.1.2.3/8 | 10/8
| 10.1.2.3/32 | 10.1.2.3/32 | 10.1.2.3 | 10.1.2.3/32
| 10.1.2/24 | 10.1.2/24 | 10.1.2.3/24 | 10.1.2/24
| 10.1/16 | 10.1/16 | 10.1.2.3/16 | 10.1/16
| 10/8 | 10/8 | 10.1.2.3/8 | 10/8
| 10/8 | 10/8 | 11.1.2.3/8 | 11/8
| 10/8 | 10/8 | 9.1.2.3/8 | 9/8
ten | cidr | network(cidr) | inet | network(inet)
-----+----------------+----------------+------------------+------------------
| 192.168.1.0/24 | 192.168.1.0/24 | 192.168.1.226/24 | 192.168.1.0/24
| 192.168.1.0/24 | 192.168.1.0/24 | 192.168.1.226 | 192.168.1.226/32
| 10.0.0.0/8 | 10.0.0.0/8 | 10.1.2.3/8 | 10.0.0.0/8
| 10.0.0.0/32 | 10.0.0.0/32 | 10.1.2.3/8 | 10.0.0.0/8
| 10.1.2.3/32 | 10.1.2.3/32 | 10.1.2.3 | 10.1.2.3/32
| 10.1.2.0/24 | 10.1.2.0/24 | 10.1.2.3/24 | 10.1.2.0/24
| 10.1.0.0/16 | 10.1.0.0/16 | 10.1.2.3/16 | 10.1.0.0/16
| 10.0.0.0/8 | 10.0.0.0/8 | 10.1.2.3/8 | 10.0.0.0/8
| 10.0.0.0/8 | 10.0.0.0/8 | 11.1.2.3/8 | 11.0.0.0/8
| 10.0.0.0/8 | 10.0.0.0/8 | 9.1.2.3/8 | 9.0.0.0/8
(10 rows)
SELECT '' AS ten, c AS cidr, masklen(c) AS "masklen(cidr)",
i AS inet, masklen(i) AS "masklen(inet)" FROM INET_TBL;
ten | cidr | masklen(cidr) | inet | masklen(inet)
-----+--------------+---------------+------------------+---------------
| 192.168.1/24 | 24 | 192.168.1.226/24 | 24
| 192.168.1/24 | 24 | 192.168.1.226 | 32
| 10/8 | 8 | 10.1.2.3/8 | 8
| 10.0.0.0/32 | 32 | 10.1.2.3/8 | 8
| 10.1.2.3/32 | 32 | 10.1.2.3 | 32
| 10.1.2/24 | 24 | 10.1.2.3/24 | 24
| 10.1/16 | 16 | 10.1.2.3/16 | 16
| 10/8 | 8 | 10.1.2.3/8 | 8
| 10/8 | 8 | 11.1.2.3/8 | 8
| 10/8 | 8 | 9.1.2.3/8 | 8
ten | cidr | masklen(cidr) | inet | masklen(inet)
-----+----------------+---------------+------------------+---------------
| 192.168.1.0/24 | 24 | 192.168.1.226/24 | 24
| 192.168.1.0/24 | 24 | 192.168.1.226 | 32
| 10.0.0.0/8 | 8 | 10.1.2.3/8 | 8
| 10.0.0.0/32 | 32 | 10.1.2.3/8 | 8
| 10.1.2.3/32 | 32 | 10.1.2.3 | 32
| 10.1.2.0/24 | 24 | 10.1.2.3/24 | 24
| 10.1.0.0/16 | 16 | 10.1.2.3/16 | 16
| 10.0.0.0/8 | 8 | 10.1.2.3/8 | 8
| 10.0.0.0/8 | 8 | 11.1.2.3/8 | 8
| 10.0.0.0/8 | 8 | 9.1.2.3/8 | 8
(10 rows)
SELECT '' AS four, c AS cidr, masklen(c) AS "masklen(cidr)",
i AS inet, masklen(i) AS "masklen(inet)" FROM INET_TBL
WHERE masklen(c) <= 8;
four | cidr | masklen(cidr) | inet | masklen(inet)
------+------+---------------+------------+---------------
| 10/8 | 8 | 10.1.2.3/8 | 8
| 10/8 | 8 | 10.1.2.3/8 | 8
| 10/8 | 8 | 11.1.2.3/8 | 8
| 10/8 | 8 | 9.1.2.3/8 | 8
four | cidr | masklen(cidr) | inet | masklen(inet)
------+------------+---------------+------------+---------------
| 10.0.0.0/8 | 8 | 10.1.2.3/8 | 8
| 10.0.0.0/8 | 8 | 10.1.2.3/8 | 8
| 10.0.0.0/8 | 8 | 11.1.2.3/8 | 8
| 10.0.0.0/8 | 8 | 9.1.2.3/8 | 8
(4 rows)
SELECT '' AS six, c AS cidr, i AS inet FROM INET_TBL
@ -121,17 +121,17 @@ SELECT '' AS ten, i, c,
i << c AS sb, i <<= c AS sbe,
i >> c AS sup, i >>= c AS spe
FROM INET_TBL;
ten | i | c | lt | le | eq | ge | gt | ne | sb | sbe | sup | spe
-----+------------------+--------------+----+----+----+----+----+----+----+-----+-----+-----
| 192.168.1.226/24 | 192.168.1/24 | f | f | f | t | t | t | f | t | f | t
| 192.168.1.226 | 192.168.1/24 | f | f | f | t | t | t | t | t | f | f
| 10.1.2.3/8 | 10/8 | f | f | f | t | t | t | f | t | f | t
| 10.1.2.3/8 | 10.0.0.0/32 | t | t | f | f | f | t | f | f | t | t
| 10.1.2.3 | 10.1.2.3/32 | f | t | t | t | f | f | f | t | f | t
| 10.1.2.3/24 | 10.1.2/24 | f | f | f | t | t | t | f | t | f | t
| 10.1.2.3/16 | 10.1/16 | f | f | f | t | t | t | f | t | f | t
| 10.1.2.3/8 | 10/8 | f | f | f | t | t | t | f | t | f | t
| 11.1.2.3/8 | 10/8 | f | f | f | t | t | t | f | f | f | f
| 9.1.2.3/8 | 10/8 | t | t | f | f | f | t | f | f | f | f
ten | i | c | lt | le | eq | ge | gt | ne | sb | sbe | sup | spe
-----+------------------+----------------+----+----+----+----+----+----+----+-----+-----+-----
| 192.168.1.226/24 | 192.168.1.0/24 | f | f | f | t | t | t | f | t | f | t
| 192.168.1.226 | 192.168.1.0/24 | f | f | f | t | t | t | t | t | f | f
| 10.1.2.3/8 | 10.0.0.0/8 | f | f | f | t | t | t | f | t | f | t
| 10.1.2.3/8 | 10.0.0.0/32 | t | t | f | f | f | t | f | f | t | t
| 10.1.2.3 | 10.1.2.3/32 | f | t | t | t | f | f | f | t | f | t
| 10.1.2.3/24 | 10.1.2.0/24 | f | f | f | t | t | t | f | t | f | t
| 10.1.2.3/16 | 10.1.0.0/16 | f | f | f | t | t | t | f | t | f | t
| 10.1.2.3/8 | 10.0.0.0/8 | f | f | f | t | t | t | f | t | f | t
| 11.1.2.3/8 | 10.0.0.0/8 | f | f | f | t | t | t | f | f | f | f
| 9.1.2.3/8 | 10.0.0.0/8 | t | t | f | f | f | t | f | f | f | f
(10 rows)