2000-01-05 07:06:23 +01:00
|
|
|
--
|
|
|
|
-- INET
|
|
|
|
--
|
|
|
|
-- prepare the table...
|
|
|
|
DROP TABLE INET_TBL;
|
2000-10-23 01:32:48 +02:00
|
|
|
ERROR: table "inet_tbl" does not exist
|
2000-01-05 07:06:23 +01:00
|
|
|
CREATE TABLE INET_TBL (c cidr, i inet);
|
|
|
|
INSERT INTO INET_TBL (c, i) VALUES ('192.168.1', '192.168.1.226/24');
|
2004-10-08 03:45:37 +02:00
|
|
|
INSERT INTO INET_TBL (c, i) VALUES ('192.168.1.0/26', '192.168.1.226');
|
2001-06-17 04:05:20 +02:00
|
|
|
INSERT INTO INET_TBL (c, i) VALUES ('192.168.1', '192.168.1.0/24');
|
|
|
|
INSERT INTO INET_TBL (c, i) VALUES ('192.168.1', '192.168.1.0/25');
|
|
|
|
INSERT INTO INET_TBL (c, i) VALUES ('192.168.1', '192.168.1.255/24');
|
|
|
|
INSERT INTO INET_TBL (c, i) VALUES ('192.168.1', '192.168.1.255/25');
|
2000-01-05 07:06:23 +01:00
|
|
|
INSERT INTO INET_TBL (c, i) VALUES ('10', '10.1.2.3/8');
|
|
|
|
INSERT INTO INET_TBL (c, i) VALUES ('10.0.0.0', '10.1.2.3/8');
|
|
|
|
INSERT INTO INET_TBL (c, i) VALUES ('10.1.2.3', '10.1.2.3/32');
|
|
|
|
INSERT INTO INET_TBL (c, i) VALUES ('10.1.2', '10.1.2.3/24');
|
|
|
|
INSERT INTO INET_TBL (c, i) VALUES ('10.1', '10.1.2.3/16');
|
|
|
|
INSERT INTO INET_TBL (c, i) VALUES ('10', '10.1.2.3/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');
|
2003-06-25 00:21:24 +02:00
|
|
|
INSERT INTO INET_TBL (c, i) VALUES ('10:23::f1', '10:23::f1/64');
|
|
|
|
INSERT INTO INET_TBL (c, i) VALUES ('10:23::8000/113', '10:23::ffff');
|
|
|
|
INSERT INTO INET_TBL (c, i) VALUES ('::ffff:1.2.3.4', '::4.3.2.1/24');
|
2000-10-27 03:55:23 +02:00
|
|
|
-- check that CIDR rejects invalid input:
|
2004-10-08 03:45:37 +02:00
|
|
|
INSERT INTO INET_TBL (c, i) VALUES ('192.168.1.2/30', '192.168.1.226');
|
|
|
|
ERROR: invalid cidr value: "192.168.1.2/30"
|
2008-09-01 22:42:46 +02:00
|
|
|
LINE 1: INSERT INTO INET_TBL (c, i) VALUES ('192.168.1.2/30', '192.1...
|
|
|
|
^
|
2003-07-27 06:53:12 +02:00
|
|
|
DETAIL: Value has bits set to right of mask.
|
2003-06-25 00:21:24 +02:00
|
|
|
INSERT INTO INET_TBL (c, i) VALUES ('1234::1234::1234', '::1.2.3.4');
|
2003-09-25 08:58:07 +02:00
|
|
|
ERROR: invalid input syntax for type cidr: "1234::1234::1234"
|
2008-09-01 22:42:46 +02:00
|
|
|
LINE 1: INSERT INTO INET_TBL (c, i) VALUES ('1234::1234::1234', '::1...
|
|
|
|
^
|
2001-06-13 23:09:00 +02:00
|
|
|
-- check that CIDR rejects invalid input when converting from text:
|
2004-10-08 03:45:37 +02:00
|
|
|
INSERT INTO INET_TBL (c, i) VALUES (cidr('192.168.1.2/30'), '192.168.1.226');
|
|
|
|
ERROR: invalid cidr value: "192.168.1.2/30"
|
2008-09-01 22:42:46 +02:00
|
|
|
LINE 1: INSERT INTO INET_TBL (c, i) VALUES (cidr('192.168.1.2/30'), ...
|
|
|
|
^
|
2003-07-27 06:53:12 +02:00
|
|
|
DETAIL: Value has bits set to right of mask.
|
2003-06-25 00:21:24 +02:00
|
|
|
INSERT INTO INET_TBL (c, i) VALUES (cidr('ffff:ffff:ffff:ffff::/24'), '::192.168.1.226');
|
2003-07-27 06:53:12 +02:00
|
|
|
ERROR: invalid cidr value: "ffff:ffff:ffff:ffff::/24"
|
2008-09-01 22:42:46 +02:00
|
|
|
LINE 1: INSERT INTO INET_TBL (c, i) VALUES (cidr('ffff:ffff:ffff:fff...
|
|
|
|
^
|
2003-07-27 06:53:12 +02:00
|
|
|
DETAIL: Value has bits set to right of mask.
|
2020-12-15 21:54:06 +01:00
|
|
|
SELECT c AS cidr, i AS inet FROM INET_TBL;
|
|
|
|
cidr | inet
|
|
|
|
--------------------+------------------
|
|
|
|
192.168.1.0/24 | 192.168.1.226/24
|
|
|
|
192.168.1.0/26 | 192.168.1.226
|
|
|
|
192.168.1.0/24 | 192.168.1.0/24
|
|
|
|
192.168.1.0/24 | 192.168.1.0/25
|
|
|
|
192.168.1.0/24 | 192.168.1.255/24
|
|
|
|
192.168.1.0/24 | 192.168.1.255/25
|
|
|
|
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:23::f1/128 | 10:23::f1/64
|
|
|
|
10:23::8000/113 | 10:23::ffff
|
|
|
|
::ffff:1.2.3.4/128 | ::4.3.2.1/24
|
2003-06-25 00:21:24 +02:00
|
|
|
(17 rows)
|
1998-10-27 20:34:18 +01:00
|
|
|
|
2000-01-05 07:06:23 +01:00
|
|
|
-- now test some support functions
|
2020-12-15 21:54:06 +01:00
|
|
|
SELECT i AS inet, host(i), text(i), family(i) FROM INET_TBL;
|
|
|
|
inet | host | text | family
|
|
|
|
------------------+---------------+------------------+--------
|
|
|
|
192.168.1.226/24 | 192.168.1.226 | 192.168.1.226/24 | 4
|
|
|
|
192.168.1.226 | 192.168.1.226 | 192.168.1.226/32 | 4
|
|
|
|
192.168.1.0/24 | 192.168.1.0 | 192.168.1.0/24 | 4
|
|
|
|
192.168.1.0/25 | 192.168.1.0 | 192.168.1.0/25 | 4
|
|
|
|
192.168.1.255/24 | 192.168.1.255 | 192.168.1.255/24 | 4
|
|
|
|
192.168.1.255/25 | 192.168.1.255 | 192.168.1.255/25 | 4
|
|
|
|
10.1.2.3/8 | 10.1.2.3 | 10.1.2.3/8 | 4
|
|
|
|
10.1.2.3/8 | 10.1.2.3 | 10.1.2.3/8 | 4
|
|
|
|
10.1.2.3 | 10.1.2.3 | 10.1.2.3/32 | 4
|
|
|
|
10.1.2.3/24 | 10.1.2.3 | 10.1.2.3/24 | 4
|
|
|
|
10.1.2.3/16 | 10.1.2.3 | 10.1.2.3/16 | 4
|
|
|
|
10.1.2.3/8 | 10.1.2.3 | 10.1.2.3/8 | 4
|
|
|
|
11.1.2.3/8 | 11.1.2.3 | 11.1.2.3/8 | 4
|
|
|
|
9.1.2.3/8 | 9.1.2.3 | 9.1.2.3/8 | 4
|
|
|
|
10:23::f1/64 | 10:23::f1 | 10:23::f1/64 | 6
|
|
|
|
10:23::ffff | 10:23::ffff | 10:23::ffff/128 | 6
|
|
|
|
::4.3.2.1/24 | ::4.3.2.1 | ::4.3.2.1/24 | 6
|
2003-06-25 00:21:24 +02:00
|
|
|
(17 rows)
|
1998-10-27 20:34:18 +01:00
|
|
|
|
2021-02-11 09:56:14 +01:00
|
|
|
SELECT c AS cidr, abbrev(c) FROM INET_TBL;
|
|
|
|
cidr | abbrev
|
|
|
|
--------------------+--------------------
|
|
|
|
192.168.1.0/24 | 192.168.1/24
|
|
|
|
192.168.1.0/26 | 192.168.1.0/26
|
|
|
|
192.168.1.0/24 | 192.168.1/24
|
|
|
|
192.168.1.0/24 | 192.168.1/24
|
|
|
|
192.168.1.0/24 | 192.168.1/24
|
|
|
|
192.168.1.0/24 | 192.168.1/24
|
|
|
|
10.0.0.0/8 | 10/8
|
|
|
|
10.0.0.0/32 | 10.0.0.0/32
|
|
|
|
10.1.2.3/32 | 10.1.2.3/32
|
|
|
|
10.1.2.0/24 | 10.1.2/24
|
|
|
|
10.1.0.0/16 | 10.1/16
|
|
|
|
10.0.0.0/8 | 10/8
|
|
|
|
10.0.0.0/8 | 10/8
|
|
|
|
10.0.0.0/8 | 10/8
|
|
|
|
10:23::f1/128 | 10:23::f1/128
|
|
|
|
10:23::8000/113 | 10:23::8000/113
|
|
|
|
::ffff:1.2.3.4/128 | ::ffff:1.2.3.4/128
|
|
|
|
(17 rows)
|
|
|
|
|
2020-12-15 21:54:06 +01:00
|
|
|
SELECT c AS cidr, broadcast(c),
|
1998-10-29 19:12:50 +01:00
|
|
|
i AS inet, broadcast(i) FROM INET_TBL;
|
2020-12-15 21:54:06 +01:00
|
|
|
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/26 | 192.168.1.63/26 | 192.168.1.226 | 192.168.1.226
|
|
|
|
192.168.1.0/24 | 192.168.1.255/24 | 192.168.1.0/24 | 192.168.1.255/24
|
|
|
|
192.168.1.0/24 | 192.168.1.255/24 | 192.168.1.0/25 | 192.168.1.127/25
|
|
|
|
192.168.1.0/24 | 192.168.1.255/24 | 192.168.1.255/24 | 192.168.1.255/24
|
|
|
|
192.168.1.0/24 | 192.168.1.255/24 | 192.168.1.255/25 | 192.168.1.255/25
|
|
|
|
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:23::f1/128 | 10:23::f1 | 10:23::f1/64 | 10:23::ffff:ffff:ffff:ffff/64
|
|
|
|
10:23::8000/113 | 10:23::ffff/113 | 10:23::ffff | 10:23::ffff
|
|
|
|
::ffff:1.2.3.4/128 | ::ffff:1.2.3.4 | ::4.3.2.1/24 | 0:ff:ffff:ffff:ffff:ffff:ffff:ffff/24
|
2003-06-25 00:21:24 +02:00
|
|
|
(17 rows)
|
1998-10-27 20:34:18 +01:00
|
|
|
|
2020-12-15 21:54:06 +01:00
|
|
|
SELECT c AS cidr, network(c) AS "network(cidr)",
|
1998-10-29 19:12:50 +01:00
|
|
|
i AS inet, network(i) AS "network(inet)" FROM INET_TBL;
|
2020-12-15 21:54:06 +01:00
|
|
|
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/26 | 192.168.1.0/26 | 192.168.1.226 | 192.168.1.226/32
|
|
|
|
192.168.1.0/24 | 192.168.1.0/24 | 192.168.1.0/24 | 192.168.1.0/24
|
|
|
|
192.168.1.0/24 | 192.168.1.0/24 | 192.168.1.0/25 | 192.168.1.0/25
|
|
|
|
192.168.1.0/24 | 192.168.1.0/24 | 192.168.1.255/24 | 192.168.1.0/24
|
|
|
|
192.168.1.0/24 | 192.168.1.0/24 | 192.168.1.255/25 | 192.168.1.128/25
|
|
|
|
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:23::f1/128 | 10:23::f1/128 | 10:23::f1/64 | 10:23::/64
|
|
|
|
10:23::8000/113 | 10:23::8000/113 | 10:23::ffff | 10:23::ffff/128
|
|
|
|
::ffff:1.2.3.4/128 | ::ffff:1.2.3.4/128 | ::4.3.2.1/24 | ::/24
|
2003-06-25 00:21:24 +02:00
|
|
|
(17 rows)
|
1998-10-27 20:34:18 +01:00
|
|
|
|
2020-12-15 21:54:06 +01:00
|
|
|
SELECT c AS cidr, masklen(c) AS "masklen(cidr)",
|
1998-10-29 19:12:50 +01:00
|
|
|
i AS inet, masklen(i) AS "masklen(inet)" FROM INET_TBL;
|
2020-12-15 21:54:06 +01:00
|
|
|
cidr | masklen(cidr) | inet | masklen(inet)
|
|
|
|
--------------------+---------------+------------------+---------------
|
|
|
|
192.168.1.0/24 | 24 | 192.168.1.226/24 | 24
|
|
|
|
192.168.1.0/26 | 26 | 192.168.1.226 | 32
|
|
|
|
192.168.1.0/24 | 24 | 192.168.1.0/24 | 24
|
|
|
|
192.168.1.0/24 | 24 | 192.168.1.0/25 | 25
|
|
|
|
192.168.1.0/24 | 24 | 192.168.1.255/24 | 24
|
|
|
|
192.168.1.0/24 | 24 | 192.168.1.255/25 | 25
|
|
|
|
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:23::f1/128 | 128 | 10:23::f1/64 | 64
|
|
|
|
10:23::8000/113 | 113 | 10:23::ffff | 128
|
|
|
|
::ffff:1.2.3.4/128 | 128 | ::4.3.2.1/24 | 24
|
2003-06-25 00:21:24 +02:00
|
|
|
(17 rows)
|
1998-10-27 20:34:18 +01:00
|
|
|
|
2020-12-15 21:54:06 +01:00
|
|
|
SELECT c AS cidr, masklen(c) AS "masklen(cidr)",
|
1998-10-29 19:12:50 +01:00
|
|
|
i AS inet, masklen(i) AS "masklen(inet)" FROM INET_TBL
|
1998-10-27 20:34:18 +01:00
|
|
|
WHERE masklen(c) <= 8;
|
2020-12-15 21:54:06 +01:00
|
|
|
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
|
1998-10-29 19:12:50 +01:00
|
|
|
(4 rows)
|
1998-10-27 20:34:18 +01:00
|
|
|
|
2020-12-15 21:54:06 +01:00
|
|
|
SELECT c AS cidr, i AS inet FROM INET_TBL
|
1998-10-27 20:34:18 +01:00
|
|
|
WHERE c = i;
|
2020-12-15 21:54:06 +01:00
|
|
|
cidr | inet
|
|
|
|
----------------+----------------
|
|
|
|
192.168.1.0/24 | 192.168.1.0/24
|
|
|
|
10.1.2.3/32 | 10.1.2.3
|
2001-06-17 04:05:20 +02:00
|
|
|
(2 rows)
|
1998-10-27 20:34:18 +01:00
|
|
|
|
2020-12-15 21:54:06 +01:00
|
|
|
SELECT i, c,
|
2010-11-23 21:27:50 +01:00
|
|
|
i < c AS lt, i <= c AS le, i = c AS eq,
|
1998-10-29 19:12:50 +01:00
|
|
|
i >= c AS ge, i > c AS gt, i <> c AS ne,
|
|
|
|
i << c AS sb, i <<= c AS sbe,
|
Add an in-core GiST index opclass for inet/cidr types.
This operator class can accelerate subnet/supernet tests as well as
btree-equivalent ordered comparisons. It also handles a new network
operator inet && inet (overlaps, a/k/a "is supernet or subnet of"),
which is expected to be useful in exclusion constraints.
Ideally this opclass would be the default for GiST with inet/cidr data,
but we can't mark it that way until we figure out how to do a more or
less graceful transition from the current situation, in which the
really-completely-bogus inet/cidr opclasses in contrib/btree_gist are
marked as default. Having the opclass in core and not default is better
than not having it at all, though.
While at it, add new documentation sections to allow us to officially
document GiST/GIN/SP-GiST opclasses, something there was never a clear
place to do before. I filled these in with some simple tables listing
the existing opclasses and the operators they support, but there's
certainly scope to put more information there.
Emre Hasegeli, reviewed by Andreas Karlsson, further hacking by me
2014-04-08 21:46:14 +02:00
|
|
|
i >> c AS sup, i >>= c AS spe,
|
|
|
|
i && c AS ovr
|
1998-10-29 19:12:50 +01:00
|
|
|
FROM INET_TBL;
|
2020-12-15 21:54:06 +01:00
|
|
|
i | c | lt | le | eq | ge | gt | ne | sb | sbe | sup | spe | ovr
|
|
|
|
------------------+--------------------+----+----+----+----+----+----+----+-----+-----+-----+-----
|
|
|
|
192.168.1.226/24 | 192.168.1.0/24 | f | f | f | t | t | t | f | t | f | t | t
|
|
|
|
192.168.1.226 | 192.168.1.0/26 | f | f | f | t | t | t | f | f | f | f | f
|
|
|
|
192.168.1.0/24 | 192.168.1.0/24 | f | t | t | t | f | f | f | t | f | t | t
|
|
|
|
192.168.1.0/25 | 192.168.1.0/24 | f | f | f | t | t | t | t | t | f | f | t
|
|
|
|
192.168.1.255/24 | 192.168.1.0/24 | f | f | f | t | t | t | f | t | f | t | t
|
|
|
|
192.168.1.255/25 | 192.168.1.0/24 | f | f | f | t | t | t | t | t | f | f | t
|
|
|
|
10.1.2.3/8 | 10.0.0.0/8 | f | f | f | t | t | t | f | t | f | t | t
|
|
|
|
10.1.2.3/8 | 10.0.0.0/32 | t | t | f | f | f | t | f | f | t | t | t
|
|
|
|
10.1.2.3 | 10.1.2.3/32 | f | t | t | t | f | f | f | t | f | t | t
|
|
|
|
10.1.2.3/24 | 10.1.2.0/24 | f | f | f | t | t | t | f | t | f | t | t
|
|
|
|
10.1.2.3/16 | 10.1.0.0/16 | f | f | f | t | t | t | f | t | f | t | t
|
|
|
|
10.1.2.3/8 | 10.0.0.0/8 | f | f | f | t | t | t | f | t | f | t | t
|
|
|
|
11.1.2.3/8 | 10.0.0.0/8 | f | f | f | t | t | t | f | f | f | f | f
|
|
|
|
9.1.2.3/8 | 10.0.0.0/8 | t | t | f | f | f | t | f | f | f | f | f
|
|
|
|
10:23::f1/64 | 10:23::f1/128 | t | t | f | f | f | t | f | f | t | t | t
|
|
|
|
10:23::ffff | 10:23::8000/113 | f | f | f | t | t | t | t | t | f | f | t
|
|
|
|
::4.3.2.1/24 | ::ffff:1.2.3.4/128 | t | t | f | f | f | t | f | f | t | t | t
|
2003-06-25 00:21:24 +02:00
|
|
|
(17 rows)
|
1998-10-29 19:12:50 +01:00
|
|
|
|
2014-08-29 04:37:58 +02:00
|
|
|
SELECT max(i) AS max, min(i) AS min FROM INET_TBL;
|
|
|
|
max | min
|
|
|
|
-------------+-----------
|
|
|
|
10:23::ffff | 9.1.2.3/8
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT max(c) AS max, min(c) AS min FROM INET_TBL;
|
|
|
|
max | min
|
|
|
|
-----------------+------------
|
|
|
|
10:23::8000/113 | 10.0.0.0/8
|
|
|
|
(1 row)
|
|
|
|
|
2001-06-13 23:09:00 +02:00
|
|
|
-- check the conversion to/from text and set_netmask
|
2020-12-15 21:54:06 +01:00
|
|
|
SELECT set_masklen(inet(text(i)), 24) FROM INET_TBL;
|
|
|
|
set_masklen
|
|
|
|
------------------
|
|
|
|
192.168.1.226/24
|
|
|
|
192.168.1.226/24
|
|
|
|
192.168.1.0/24
|
|
|
|
192.168.1.0/24
|
|
|
|
192.168.1.255/24
|
|
|
|
192.168.1.255/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:23::f1/24
|
|
|
|
10:23::ffff/24
|
|
|
|
::4.3.2.1/24
|
2003-06-25 00:21:24 +02:00
|
|
|
(17 rows)
|
2001-06-17 04:05:20 +02:00
|
|
|
|
Add an in-core GiST index opclass for inet/cidr types.
This operator class can accelerate subnet/supernet tests as well as
btree-equivalent ordered comparisons. It also handles a new network
operator inet && inet (overlaps, a/k/a "is supernet or subnet of"),
which is expected to be useful in exclusion constraints.
Ideally this opclass would be the default for GiST with inet/cidr data,
but we can't mark it that way until we figure out how to do a more or
less graceful transition from the current situation, in which the
really-completely-bogus inet/cidr opclasses in contrib/btree_gist are
marked as default. Having the opclass in core and not default is better
than not having it at all, though.
While at it, add new documentation sections to allow us to officially
document GiST/GIN/SP-GiST opclasses, something there was never a clear
place to do before. I filled these in with some simple tables listing
the existing opclasses and the operators they support, but there's
certainly scope to put more information there.
Emre Hasegeli, reviewed by Andreas Karlsson, further hacking by me
2014-04-08 21:46:14 +02:00
|
|
|
-- check that btree index works correctly
|
2003-01-15 17:35:50 +01:00
|
|
|
CREATE INDEX inet_idx1 ON inet_tbl(i);
|
|
|
|
SET enable_seqscan TO off;
|
2019-02-12 03:26:08 +01:00
|
|
|
EXPLAIN (COSTS OFF)
|
|
|
|
SELECT * FROM inet_tbl WHERE i<<'192.168.1.0/24'::cidr;
|
|
|
|
QUERY PLAN
|
|
|
|
-------------------------------------------------------------------------------
|
|
|
|
Index Scan using inet_idx1 on inet_tbl
|
|
|
|
Index Cond: ((i > '192.168.1.0/24'::inet) AND (i <= '192.168.1.255'::inet))
|
|
|
|
Filter: (i << '192.168.1.0/24'::inet)
|
|
|
|
(3 rows)
|
|
|
|
|
2003-01-15 21:01:01 +01:00
|
|
|
SELECT * FROM inet_tbl WHERE i<<'192.168.1.0/24'::cidr;
|
2001-06-17 04:05:20 +02:00
|
|
|
c | i
|
|
|
|
----------------+------------------
|
2006-02-12 04:10:04 +01:00
|
|
|
192.168.1.0/24 | 192.168.1.0/25
|
2001-06-17 04:05:20 +02:00
|
|
|
192.168.1.0/24 | 192.168.1.255/25
|
2006-02-12 04:10:04 +01:00
|
|
|
192.168.1.0/26 | 192.168.1.226
|
2001-06-17 04:05:20 +02:00
|
|
|
(3 rows)
|
|
|
|
|
2019-02-12 03:26:08 +01:00
|
|
|
EXPLAIN (COSTS OFF)
|
|
|
|
SELECT * FROM inet_tbl WHERE i<<='192.168.1.0/24'::cidr;
|
|
|
|
QUERY PLAN
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
Index Scan using inet_idx1 on inet_tbl
|
|
|
|
Index Cond: ((i >= '192.168.1.0/24'::inet) AND (i <= '192.168.1.255'::inet))
|
|
|
|
Filter: (i <<= '192.168.1.0/24'::inet)
|
|
|
|
(3 rows)
|
|
|
|
|
2003-01-15 21:01:01 +01:00
|
|
|
SELECT * FROM inet_tbl WHERE i<<='192.168.1.0/24'::cidr;
|
2001-06-17 04:05:20 +02:00
|
|
|
c | i
|
|
|
|
----------------+------------------
|
2006-02-12 04:10:04 +01:00
|
|
|
192.168.1.0/24 | 192.168.1.0/24
|
2001-06-17 04:05:20 +02:00
|
|
|
192.168.1.0/24 | 192.168.1.226/24
|
|
|
|
192.168.1.0/24 | 192.168.1.255/24
|
2006-02-12 04:10:04 +01:00
|
|
|
192.168.1.0/24 | 192.168.1.0/25
|
2001-06-17 04:05:20 +02:00
|
|
|
192.168.1.0/24 | 192.168.1.255/25
|
2006-02-12 04:10:04 +01:00
|
|
|
192.168.1.0/26 | 192.168.1.226
|
2001-06-17 04:05:20 +02:00
|
|
|
(6 rows)
|
2001-06-13 23:09:00 +02:00
|
|
|
|
2019-02-12 03:26:08 +01:00
|
|
|
EXPLAIN (COSTS OFF)
|
|
|
|
SELECT * FROM inet_tbl WHERE '192.168.1.0/24'::cidr >>= i;
|
|
|
|
QUERY PLAN
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
Index Scan using inet_idx1 on inet_tbl
|
|
|
|
Index Cond: ((i >= '192.168.1.0/24'::inet) AND (i <= '192.168.1.255'::inet))
|
|
|
|
Filter: ('192.168.1.0/24'::inet >>= i)
|
|
|
|
(3 rows)
|
|
|
|
|
|
|
|
SELECT * FROM inet_tbl WHERE '192.168.1.0/24'::cidr >>= i;
|
|
|
|
c | i
|
|
|
|
----------------+------------------
|
|
|
|
192.168.1.0/24 | 192.168.1.0/24
|
|
|
|
192.168.1.0/24 | 192.168.1.226/24
|
|
|
|
192.168.1.0/24 | 192.168.1.255/24
|
|
|
|
192.168.1.0/24 | 192.168.1.0/25
|
|
|
|
192.168.1.0/24 | 192.168.1.255/25
|
|
|
|
192.168.1.0/26 | 192.168.1.226
|
|
|
|
(6 rows)
|
|
|
|
|
|
|
|
EXPLAIN (COSTS OFF)
|
|
|
|
SELECT * FROM inet_tbl WHERE '192.168.1.0/24'::cidr >> i;
|
|
|
|
QUERY PLAN
|
|
|
|
-------------------------------------------------------------------------------
|
|
|
|
Index Scan using inet_idx1 on inet_tbl
|
|
|
|
Index Cond: ((i > '192.168.1.0/24'::inet) AND (i <= '192.168.1.255'::inet))
|
|
|
|
Filter: ('192.168.1.0/24'::inet >> i)
|
|
|
|
(3 rows)
|
|
|
|
|
|
|
|
SELECT * FROM inet_tbl WHERE '192.168.1.0/24'::cidr >> i;
|
|
|
|
c | i
|
|
|
|
----------------+------------------
|
|
|
|
192.168.1.0/24 | 192.168.1.0/25
|
|
|
|
192.168.1.0/24 | 192.168.1.255/25
|
|
|
|
192.168.1.0/26 | 192.168.1.226
|
|
|
|
(3 rows)
|
|
|
|
|
2006-02-11 21:39:59 +01:00
|
|
|
SET enable_seqscan TO on;
|
|
|
|
DROP INDEX inet_idx1;
|
Add an in-core GiST index opclass for inet/cidr types.
This operator class can accelerate subnet/supernet tests as well as
btree-equivalent ordered comparisons. It also handles a new network
operator inet && inet (overlaps, a/k/a "is supernet or subnet of"),
which is expected to be useful in exclusion constraints.
Ideally this opclass would be the default for GiST with inet/cidr data,
but we can't mark it that way until we figure out how to do a more or
less graceful transition from the current situation, in which the
really-completely-bogus inet/cidr opclasses in contrib/btree_gist are
marked as default. Having the opclass in core and not default is better
than not having it at all, though.
While at it, add new documentation sections to allow us to officially
document GiST/GIN/SP-GiST opclasses, something there was never a clear
place to do before. I filled these in with some simple tables listing
the existing opclasses and the operators they support, but there's
certainly scope to put more information there.
Emre Hasegeli, reviewed by Andreas Karlsson, further hacking by me
2014-04-08 21:46:14 +02:00
|
|
|
-- check that gist index works correctly
|
|
|
|
CREATE INDEX inet_idx2 ON inet_tbl using gist (i inet_ops);
|
|
|
|
SET enable_seqscan TO off;
|
|
|
|
SELECT * FROM inet_tbl WHERE i << '192.168.1.0/24'::cidr ORDER BY i;
|
|
|
|
c | i
|
|
|
|
----------------+------------------
|
|
|
|
192.168.1.0/24 | 192.168.1.0/25
|
|
|
|
192.168.1.0/24 | 192.168.1.255/25
|
|
|
|
192.168.1.0/26 | 192.168.1.226
|
|
|
|
(3 rows)
|
|
|
|
|
|
|
|
SELECT * FROM inet_tbl WHERE i <<= '192.168.1.0/24'::cidr ORDER BY i;
|
|
|
|
c | i
|
|
|
|
----------------+------------------
|
|
|
|
192.168.1.0/24 | 192.168.1.0/24
|
|
|
|
192.168.1.0/24 | 192.168.1.226/24
|
|
|
|
192.168.1.0/24 | 192.168.1.255/24
|
|
|
|
192.168.1.0/24 | 192.168.1.0/25
|
|
|
|
192.168.1.0/24 | 192.168.1.255/25
|
|
|
|
192.168.1.0/26 | 192.168.1.226
|
|
|
|
(6 rows)
|
|
|
|
|
|
|
|
SELECT * FROM inet_tbl WHERE i && '192.168.1.0/24'::cidr ORDER BY i;
|
|
|
|
c | i
|
|
|
|
----------------+------------------
|
|
|
|
192.168.1.0/24 | 192.168.1.0/24
|
|
|
|
192.168.1.0/24 | 192.168.1.226/24
|
|
|
|
192.168.1.0/24 | 192.168.1.255/24
|
|
|
|
192.168.1.0/24 | 192.168.1.0/25
|
|
|
|
192.168.1.0/24 | 192.168.1.255/25
|
|
|
|
192.168.1.0/26 | 192.168.1.226
|
|
|
|
(6 rows)
|
|
|
|
|
|
|
|
SELECT * FROM inet_tbl WHERE i >>= '192.168.1.0/24'::cidr ORDER BY i;
|
|
|
|
c | i
|
|
|
|
----------------+------------------
|
|
|
|
192.168.1.0/24 | 192.168.1.0/24
|
|
|
|
192.168.1.0/24 | 192.168.1.226/24
|
|
|
|
192.168.1.0/24 | 192.168.1.255/24
|
|
|
|
(3 rows)
|
|
|
|
|
|
|
|
SELECT * FROM inet_tbl WHERE i >> '192.168.1.0/24'::cidr ORDER BY i;
|
|
|
|
c | i
|
|
|
|
---+---
|
|
|
|
(0 rows)
|
|
|
|
|
|
|
|
SELECT * FROM inet_tbl WHERE i < '192.168.1.0/24'::cidr ORDER BY i;
|
|
|
|
c | i
|
|
|
|
-------------+-------------
|
|
|
|
10.0.0.0/8 | 9.1.2.3/8
|
|
|
|
10.0.0.0/32 | 10.1.2.3/8
|
|
|
|
10.0.0.0/8 | 10.1.2.3/8
|
|
|
|
10.0.0.0/8 | 10.1.2.3/8
|
|
|
|
10.1.0.0/16 | 10.1.2.3/16
|
|
|
|
10.1.2.0/24 | 10.1.2.3/24
|
|
|
|
10.1.2.3/32 | 10.1.2.3
|
|
|
|
10.0.0.0/8 | 11.1.2.3/8
|
|
|
|
(8 rows)
|
|
|
|
|
|
|
|
SELECT * FROM inet_tbl WHERE i <= '192.168.1.0/24'::cidr ORDER BY i;
|
|
|
|
c | i
|
|
|
|
----------------+----------------
|
|
|
|
10.0.0.0/8 | 9.1.2.3/8
|
|
|
|
10.0.0.0/8 | 10.1.2.3/8
|
|
|
|
10.0.0.0/32 | 10.1.2.3/8
|
|
|
|
10.0.0.0/8 | 10.1.2.3/8
|
|
|
|
10.1.0.0/16 | 10.1.2.3/16
|
|
|
|
10.1.2.0/24 | 10.1.2.3/24
|
|
|
|
10.1.2.3/32 | 10.1.2.3
|
|
|
|
10.0.0.0/8 | 11.1.2.3/8
|
|
|
|
192.168.1.0/24 | 192.168.1.0/24
|
|
|
|
(9 rows)
|
|
|
|
|
|
|
|
SELECT * FROM inet_tbl WHERE i = '192.168.1.0/24'::cidr ORDER BY i;
|
|
|
|
c | i
|
|
|
|
----------------+----------------
|
|
|
|
192.168.1.0/24 | 192.168.1.0/24
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT * FROM inet_tbl WHERE i >= '192.168.1.0/24'::cidr ORDER BY i;
|
|
|
|
c | i
|
|
|
|
--------------------+------------------
|
|
|
|
192.168.1.0/24 | 192.168.1.0/24
|
|
|
|
192.168.1.0/24 | 192.168.1.226/24
|
|
|
|
192.168.1.0/24 | 192.168.1.255/24
|
|
|
|
192.168.1.0/24 | 192.168.1.0/25
|
|
|
|
192.168.1.0/24 | 192.168.1.255/25
|
|
|
|
192.168.1.0/26 | 192.168.1.226
|
|
|
|
::ffff:1.2.3.4/128 | ::4.3.2.1/24
|
|
|
|
10:23::f1/128 | 10:23::f1/64
|
|
|
|
10:23::8000/113 | 10:23::ffff
|
|
|
|
(9 rows)
|
|
|
|
|
|
|
|
SELECT * FROM inet_tbl WHERE i > '192.168.1.0/24'::cidr ORDER BY i;
|
|
|
|
c | i
|
|
|
|
--------------------+------------------
|
|
|
|
192.168.1.0/24 | 192.168.1.226/24
|
|
|
|
192.168.1.0/24 | 192.168.1.255/24
|
|
|
|
192.168.1.0/24 | 192.168.1.0/25
|
|
|
|
192.168.1.0/24 | 192.168.1.255/25
|
|
|
|
192.168.1.0/26 | 192.168.1.226
|
|
|
|
::ffff:1.2.3.4/128 | ::4.3.2.1/24
|
|
|
|
10:23::f1/128 | 10:23::f1/64
|
|
|
|
10:23::8000/113 | 10:23::ffff
|
|
|
|
(8 rows)
|
|
|
|
|
|
|
|
SELECT * FROM inet_tbl WHERE i <> '192.168.1.0/24'::cidr ORDER BY i;
|
|
|
|
c | i
|
|
|
|
--------------------+------------------
|
|
|
|
10.0.0.0/8 | 9.1.2.3/8
|
|
|
|
10.0.0.0/8 | 10.1.2.3/8
|
|
|
|
10.0.0.0/32 | 10.1.2.3/8
|
|
|
|
10.0.0.0/8 | 10.1.2.3/8
|
|
|
|
10.1.0.0/16 | 10.1.2.3/16
|
|
|
|
10.1.2.0/24 | 10.1.2.3/24
|
|
|
|
10.1.2.3/32 | 10.1.2.3
|
|
|
|
10.0.0.0/8 | 11.1.2.3/8
|
|
|
|
192.168.1.0/24 | 192.168.1.226/24
|
|
|
|
192.168.1.0/24 | 192.168.1.255/24
|
|
|
|
192.168.1.0/24 | 192.168.1.0/25
|
|
|
|
192.168.1.0/24 | 192.168.1.255/25
|
|
|
|
192.168.1.0/26 | 192.168.1.226
|
|
|
|
::ffff:1.2.3.4/128 | ::4.3.2.1/24
|
|
|
|
10:23::f1/128 | 10:23::f1/64
|
|
|
|
10:23::8000/113 | 10:23::ffff
|
|
|
|
(16 rows)
|
|
|
|
|
2015-03-28 14:11:53 +01:00
|
|
|
-- test index-only scans
|
|
|
|
EXPLAIN (COSTS OFF)
|
|
|
|
SELECT i FROM inet_tbl WHERE i << '192.168.1.0/24'::cidr ORDER BY i;
|
|
|
|
QUERY PLAN
|
|
|
|
---------------------------------------------------
|
|
|
|
Sort
|
|
|
|
Sort Key: i
|
|
|
|
-> Index Only Scan using inet_idx2 on inet_tbl
|
|
|
|
Index Cond: (i << '192.168.1.0/24'::inet)
|
|
|
|
(4 rows)
|
|
|
|
|
|
|
|
SELECT i FROM inet_tbl WHERE i << '192.168.1.0/24'::cidr ORDER BY i;
|
|
|
|
i
|
|
|
|
------------------
|
|
|
|
192.168.1.0/25
|
|
|
|
192.168.1.255/25
|
|
|
|
192.168.1.226
|
|
|
|
(3 rows)
|
|
|
|
|
Add an in-core GiST index opclass for inet/cidr types.
This operator class can accelerate subnet/supernet tests as well as
btree-equivalent ordered comparisons. It also handles a new network
operator inet && inet (overlaps, a/k/a "is supernet or subnet of"),
which is expected to be useful in exclusion constraints.
Ideally this opclass would be the default for GiST with inet/cidr data,
but we can't mark it that way until we figure out how to do a more or
less graceful transition from the current situation, in which the
really-completely-bogus inet/cidr opclasses in contrib/btree_gist are
marked as default. Having the opclass in core and not default is better
than not having it at all, though.
While at it, add new documentation sections to allow us to officially
document GiST/GIN/SP-GiST opclasses, something there was never a clear
place to do before. I filled these in with some simple tables listing
the existing opclasses and the operators they support, but there's
certainly scope to put more information there.
Emre Hasegeli, reviewed by Andreas Karlsson, further hacking by me
2014-04-08 21:46:14 +02:00
|
|
|
SET enable_seqscan TO on;
|
|
|
|
DROP INDEX inet_idx2;
|
2016-08-23 21:16:21 +02:00
|
|
|
-- check that spgist index works correctly
|
|
|
|
CREATE INDEX inet_idx3 ON inet_tbl using spgist (i);
|
|
|
|
SET enable_seqscan TO off;
|
|
|
|
SELECT * FROM inet_tbl WHERE i << '192.168.1.0/24'::cidr ORDER BY i;
|
|
|
|
c | i
|
|
|
|
----------------+------------------
|
|
|
|
192.168.1.0/24 | 192.168.1.0/25
|
|
|
|
192.168.1.0/24 | 192.168.1.255/25
|
|
|
|
192.168.1.0/26 | 192.168.1.226
|
|
|
|
(3 rows)
|
|
|
|
|
|
|
|
SELECT * FROM inet_tbl WHERE i <<= '192.168.1.0/24'::cidr ORDER BY i;
|
|
|
|
c | i
|
|
|
|
----------------+------------------
|
|
|
|
192.168.1.0/24 | 192.168.1.0/24
|
|
|
|
192.168.1.0/24 | 192.168.1.226/24
|
|
|
|
192.168.1.0/24 | 192.168.1.255/24
|
|
|
|
192.168.1.0/24 | 192.168.1.0/25
|
|
|
|
192.168.1.0/24 | 192.168.1.255/25
|
|
|
|
192.168.1.0/26 | 192.168.1.226
|
|
|
|
(6 rows)
|
|
|
|
|
|
|
|
SELECT * FROM inet_tbl WHERE i && '192.168.1.0/24'::cidr ORDER BY i;
|
|
|
|
c | i
|
|
|
|
----------------+------------------
|
|
|
|
192.168.1.0/24 | 192.168.1.0/24
|
|
|
|
192.168.1.0/24 | 192.168.1.226/24
|
|
|
|
192.168.1.0/24 | 192.168.1.255/24
|
|
|
|
192.168.1.0/24 | 192.168.1.0/25
|
|
|
|
192.168.1.0/24 | 192.168.1.255/25
|
|
|
|
192.168.1.0/26 | 192.168.1.226
|
|
|
|
(6 rows)
|
|
|
|
|
|
|
|
SELECT * FROM inet_tbl WHERE i >>= '192.168.1.0/24'::cidr ORDER BY i;
|
|
|
|
c | i
|
|
|
|
----------------+------------------
|
|
|
|
192.168.1.0/24 | 192.168.1.0/24
|
|
|
|
192.168.1.0/24 | 192.168.1.226/24
|
|
|
|
192.168.1.0/24 | 192.168.1.255/24
|
|
|
|
(3 rows)
|
|
|
|
|
|
|
|
SELECT * FROM inet_tbl WHERE i >> '192.168.1.0/24'::cidr ORDER BY i;
|
|
|
|
c | i
|
|
|
|
---+---
|
|
|
|
(0 rows)
|
|
|
|
|
|
|
|
SELECT * FROM inet_tbl WHERE i < '192.168.1.0/24'::cidr ORDER BY i;
|
|
|
|
c | i
|
|
|
|
-------------+-------------
|
|
|
|
10.0.0.0/8 | 9.1.2.3/8
|
|
|
|
10.0.0.0/32 | 10.1.2.3/8
|
|
|
|
10.0.0.0/8 | 10.1.2.3/8
|
|
|
|
10.0.0.0/8 | 10.1.2.3/8
|
|
|
|
10.1.0.0/16 | 10.1.2.3/16
|
|
|
|
10.1.2.0/24 | 10.1.2.3/24
|
|
|
|
10.1.2.3/32 | 10.1.2.3
|
|
|
|
10.0.0.0/8 | 11.1.2.3/8
|
|
|
|
(8 rows)
|
|
|
|
|
|
|
|
SELECT * FROM inet_tbl WHERE i <= '192.168.1.0/24'::cidr ORDER BY i;
|
|
|
|
c | i
|
|
|
|
----------------+----------------
|
|
|
|
10.0.0.0/8 | 9.1.2.3/8
|
|
|
|
10.0.0.0/8 | 10.1.2.3/8
|
|
|
|
10.0.0.0/32 | 10.1.2.3/8
|
|
|
|
10.0.0.0/8 | 10.1.2.3/8
|
|
|
|
10.1.0.0/16 | 10.1.2.3/16
|
|
|
|
10.1.2.0/24 | 10.1.2.3/24
|
|
|
|
10.1.2.3/32 | 10.1.2.3
|
|
|
|
10.0.0.0/8 | 11.1.2.3/8
|
|
|
|
192.168.1.0/24 | 192.168.1.0/24
|
|
|
|
(9 rows)
|
|
|
|
|
|
|
|
SELECT * FROM inet_tbl WHERE i = '192.168.1.0/24'::cidr ORDER BY i;
|
|
|
|
c | i
|
|
|
|
----------------+----------------
|
|
|
|
192.168.1.0/24 | 192.168.1.0/24
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT * FROM inet_tbl WHERE i >= '192.168.1.0/24'::cidr ORDER BY i;
|
|
|
|
c | i
|
|
|
|
--------------------+------------------
|
|
|
|
192.168.1.0/24 | 192.168.1.0/24
|
|
|
|
192.168.1.0/24 | 192.168.1.226/24
|
|
|
|
192.168.1.0/24 | 192.168.1.255/24
|
|
|
|
192.168.1.0/24 | 192.168.1.0/25
|
|
|
|
192.168.1.0/24 | 192.168.1.255/25
|
|
|
|
192.168.1.0/26 | 192.168.1.226
|
|
|
|
::ffff:1.2.3.4/128 | ::4.3.2.1/24
|
|
|
|
10:23::f1/128 | 10:23::f1/64
|
|
|
|
10:23::8000/113 | 10:23::ffff
|
|
|
|
(9 rows)
|
|
|
|
|
|
|
|
SELECT * FROM inet_tbl WHERE i > '192.168.1.0/24'::cidr ORDER BY i;
|
|
|
|
c | i
|
|
|
|
--------------------+------------------
|
|
|
|
192.168.1.0/24 | 192.168.1.226/24
|
|
|
|
192.168.1.0/24 | 192.168.1.255/24
|
|
|
|
192.168.1.0/24 | 192.168.1.0/25
|
|
|
|
192.168.1.0/24 | 192.168.1.255/25
|
|
|
|
192.168.1.0/26 | 192.168.1.226
|
|
|
|
::ffff:1.2.3.4/128 | ::4.3.2.1/24
|
|
|
|
10:23::f1/128 | 10:23::f1/64
|
|
|
|
10:23::8000/113 | 10:23::ffff
|
|
|
|
(8 rows)
|
|
|
|
|
|
|
|
SELECT * FROM inet_tbl WHERE i <> '192.168.1.0/24'::cidr ORDER BY i;
|
|
|
|
c | i
|
|
|
|
--------------------+------------------
|
|
|
|
10.0.0.0/8 | 9.1.2.3/8
|
|
|
|
10.0.0.0/8 | 10.1.2.3/8
|
|
|
|
10.0.0.0/32 | 10.1.2.3/8
|
|
|
|
10.0.0.0/8 | 10.1.2.3/8
|
|
|
|
10.1.0.0/16 | 10.1.2.3/16
|
|
|
|
10.1.2.0/24 | 10.1.2.3/24
|
|
|
|
10.1.2.3/32 | 10.1.2.3
|
|
|
|
10.0.0.0/8 | 11.1.2.3/8
|
|
|
|
192.168.1.0/24 | 192.168.1.226/24
|
|
|
|
192.168.1.0/24 | 192.168.1.255/24
|
|
|
|
192.168.1.0/24 | 192.168.1.0/25
|
|
|
|
192.168.1.0/24 | 192.168.1.255/25
|
|
|
|
192.168.1.0/26 | 192.168.1.226
|
|
|
|
::ffff:1.2.3.4/128 | ::4.3.2.1/24
|
|
|
|
10:23::f1/128 | 10:23::f1/64
|
|
|
|
10:23::8000/113 | 10:23::ffff
|
|
|
|
(16 rows)
|
|
|
|
|
|
|
|
-- test index-only scans
|
|
|
|
EXPLAIN (COSTS OFF)
|
|
|
|
SELECT i FROM inet_tbl WHERE i << '192.168.1.0/24'::cidr ORDER BY i;
|
|
|
|
QUERY PLAN
|
|
|
|
---------------------------------------------------
|
|
|
|
Sort
|
|
|
|
Sort Key: i
|
|
|
|
-> Index Only Scan using inet_idx3 on inet_tbl
|
|
|
|
Index Cond: (i << '192.168.1.0/24'::inet)
|
|
|
|
(4 rows)
|
|
|
|
|
|
|
|
SELECT i FROM inet_tbl WHERE i << '192.168.1.0/24'::cidr ORDER BY i;
|
|
|
|
i
|
|
|
|
------------------
|
|
|
|
192.168.1.0/25
|
|
|
|
192.168.1.255/25
|
|
|
|
192.168.1.226
|
|
|
|
(3 rows)
|
|
|
|
|
|
|
|
SET enable_seqscan TO on;
|
|
|
|
DROP INDEX inet_idx3;
|
2006-02-11 21:39:59 +01:00
|
|
|
-- simple tests of inet boolean and arithmetic operators
|
|
|
|
SELECT i, ~i AS "~i" FROM inet_tbl;
|
|
|
|
i | ~i
|
|
|
|
------------------+--------------------------------------------
|
2006-02-12 04:10:04 +01:00
|
|
|
192.168.1.226/24 | 63.87.254.29/24
|
|
|
|
192.168.1.226 | 63.87.254.29
|
|
|
|
192.168.1.0/24 | 63.87.254.255/24
|
|
|
|
192.168.1.0/25 | 63.87.254.255/25
|
|
|
|
192.168.1.255/24 | 63.87.254.0/24
|
|
|
|
192.168.1.255/25 | 63.87.254.0/25
|
|
|
|
10.1.2.3/8 | 245.254.253.252/8
|
|
|
|
10.1.2.3/8 | 245.254.253.252/8
|
|
|
|
10.1.2.3 | 245.254.253.252
|
|
|
|
10.1.2.3/24 | 245.254.253.252/24
|
|
|
|
10.1.2.3/16 | 245.254.253.252/16
|
|
|
|
10.1.2.3/8 | 245.254.253.252/8
|
|
|
|
11.1.2.3/8 | 244.254.253.252/8
|
|
|
|
9.1.2.3/8 | 246.254.253.252/8
|
2006-02-11 21:39:59 +01:00
|
|
|
10:23::f1/64 | ffef:ffdc:ffff:ffff:ffff:ffff:ffff:ff0e/64
|
2006-02-12 04:10:04 +01:00
|
|
|
10:23::ffff | ffef:ffdc:ffff:ffff:ffff:ffff:ffff:0
|
2006-02-11 21:39:59 +01:00
|
|
|
::4.3.2.1/24 | ffff:ffff:ffff:ffff:ffff:ffff:fbfc:fdfe/24
|
2006-02-11 04:32:41 +01:00
|
|
|
(17 rows)
|
|
|
|
|
2006-02-11 21:39:59 +01:00
|
|
|
SELECT i, c, i & c AS "and" FROM inet_tbl;
|
|
|
|
i | c | and
|
|
|
|
------------------+--------------------+----------------
|
|
|
|
192.168.1.226/24 | 192.168.1.0/24 | 192.168.1.0/24
|
2006-02-12 04:10:04 +01:00
|
|
|
192.168.1.226 | 192.168.1.0/26 | 192.168.1.0
|
2006-02-11 21:39:59 +01:00
|
|
|
192.168.1.0/24 | 192.168.1.0/24 | 192.168.1.0/24
|
|
|
|
192.168.1.0/25 | 192.168.1.0/24 | 192.168.1.0/25
|
|
|
|
192.168.1.255/24 | 192.168.1.0/24 | 192.168.1.0/24
|
|
|
|
192.168.1.255/25 | 192.168.1.0/24 | 192.168.1.0/25
|
2006-02-12 04:10:04 +01:00
|
|
|
10.1.2.3/8 | 10.0.0.0/8 | 10.0.0.0/8
|
|
|
|
10.1.2.3/8 | 10.0.0.0/32 | 10.0.0.0
|
|
|
|
10.1.2.3 | 10.1.2.3/32 | 10.1.2.3
|
|
|
|
10.1.2.3/24 | 10.1.2.0/24 | 10.1.2.0/24
|
|
|
|
10.1.2.3/16 | 10.1.0.0/16 | 10.1.0.0/16
|
|
|
|
10.1.2.3/8 | 10.0.0.0/8 | 10.0.0.0/8
|
|
|
|
11.1.2.3/8 | 10.0.0.0/8 | 10.0.0.0/8
|
|
|
|
9.1.2.3/8 | 10.0.0.0/8 | 8.0.0.0/8
|
|
|
|
10:23::f1/64 | 10:23::f1/128 | 10:23::f1
|
|
|
|
10:23::ffff | 10:23::8000/113 | 10:23::8000
|
|
|
|
::4.3.2.1/24 | ::ffff:1.2.3.4/128 | ::0.2.2.0
|
2006-02-11 04:32:41 +01:00
|
|
|
(17 rows)
|
|
|
|
|
2006-02-11 21:39:59 +01:00
|
|
|
SELECT i, c, i | c AS "or" FROM inet_tbl;
|
|
|
|
i | c | or
|
|
|
|
------------------+--------------------+------------------
|
|
|
|
192.168.1.226/24 | 192.168.1.0/24 | 192.168.1.226/24
|
2006-02-12 04:10:04 +01:00
|
|
|
192.168.1.226 | 192.168.1.0/26 | 192.168.1.226
|
|
|
|
192.168.1.0/24 | 192.168.1.0/24 | 192.168.1.0/24
|
|
|
|
192.168.1.0/25 | 192.168.1.0/24 | 192.168.1.0/25
|
2006-02-11 21:39:59 +01:00
|
|
|
192.168.1.255/24 | 192.168.1.0/24 | 192.168.1.255/24
|
|
|
|
192.168.1.255/25 | 192.168.1.0/24 | 192.168.1.255/25
|
2006-02-12 04:10:04 +01:00
|
|
|
10.1.2.3/8 | 10.0.0.0/8 | 10.1.2.3/8
|
|
|
|
10.1.2.3/8 | 10.0.0.0/32 | 10.1.2.3
|
|
|
|
10.1.2.3 | 10.1.2.3/32 | 10.1.2.3
|
|
|
|
10.1.2.3/24 | 10.1.2.0/24 | 10.1.2.3/24
|
|
|
|
10.1.2.3/16 | 10.1.0.0/16 | 10.1.2.3/16
|
|
|
|
10.1.2.3/8 | 10.0.0.0/8 | 10.1.2.3/8
|
|
|
|
11.1.2.3/8 | 10.0.0.0/8 | 11.1.2.3/8
|
|
|
|
9.1.2.3/8 | 10.0.0.0/8 | 11.1.2.3/8
|
|
|
|
10:23::f1/64 | 10:23::f1/128 | 10:23::f1
|
|
|
|
10:23::ffff | 10:23::8000/113 | 10:23::ffff
|
|
|
|
::4.3.2.1/24 | ::ffff:1.2.3.4/128 | ::ffff:5.3.3.5
|
2006-02-11 04:32:41 +01:00
|
|
|
(17 rows)
|
|
|
|
|
2006-02-11 21:39:59 +01:00
|
|
|
SELECT i, i + 500 AS "i+500" FROM inet_tbl;
|
|
|
|
i | i+500
|
|
|
|
------------------+------------------
|
|
|
|
192.168.1.226/24 | 192.168.3.214/24
|
2006-02-12 04:10:04 +01:00
|
|
|
192.168.1.226 | 192.168.3.214
|
2006-02-11 21:39:59 +01:00
|
|
|
192.168.1.0/24 | 192.168.2.244/24
|
|
|
|
192.168.1.0/25 | 192.168.2.244/25
|
|
|
|
192.168.1.255/24 | 192.168.3.243/24
|
|
|
|
192.168.1.255/25 | 192.168.3.243/25
|
2006-02-12 04:10:04 +01:00
|
|
|
10.1.2.3/8 | 10.1.3.247/8
|
|
|
|
10.1.2.3/8 | 10.1.3.247/8
|
|
|
|
10.1.2.3 | 10.1.3.247
|
|
|
|
10.1.2.3/24 | 10.1.3.247/24
|
|
|
|
10.1.2.3/16 | 10.1.3.247/16
|
|
|
|
10.1.2.3/8 | 10.1.3.247/8
|
|
|
|
11.1.2.3/8 | 11.1.3.247/8
|
|
|
|
9.1.2.3/8 | 9.1.3.247/8
|
|
|
|
10:23::f1/64 | 10:23::2e5/64
|
|
|
|
10:23::ffff | 10:23::1:1f3
|
|
|
|
::4.3.2.1/24 | ::4.3.3.245/24
|
2006-02-11 04:32:41 +01:00
|
|
|
(17 rows)
|
|
|
|
|
2006-02-11 21:39:59 +01:00
|
|
|
SELECT i, i - 500 AS "i-500" FROM inet_tbl;
|
|
|
|
i | i-500
|
|
|
|
------------------+----------------------------------------
|
2006-02-12 04:10:04 +01:00
|
|
|
192.168.1.226/24 | 192.167.255.238/24
|
|
|
|
192.168.1.226 | 192.167.255.238
|
|
|
|
192.168.1.0/24 | 192.167.255.12/24
|
|
|
|
192.168.1.0/25 | 192.167.255.12/25
|
|
|
|
192.168.1.255/24 | 192.168.0.11/24
|
|
|
|
192.168.1.255/25 | 192.168.0.11/25
|
|
|
|
10.1.2.3/8 | 10.1.0.15/8
|
|
|
|
10.1.2.3/8 | 10.1.0.15/8
|
|
|
|
10.1.2.3 | 10.1.0.15
|
|
|
|
10.1.2.3/24 | 10.1.0.15/24
|
|
|
|
10.1.2.3/16 | 10.1.0.15/16
|
|
|
|
10.1.2.3/8 | 10.1.0.15/8
|
|
|
|
11.1.2.3/8 | 11.1.0.15/8
|
|
|
|
9.1.2.3/8 | 9.1.0.15/8
|
2006-02-11 21:39:59 +01:00
|
|
|
10:23::f1/64 | 10:22:ffff:ffff:ffff:ffff:ffff:fefd/64
|
2006-02-12 04:10:04 +01:00
|
|
|
10:23::ffff | 10:23::fe0b
|
|
|
|
::4.3.2.1/24 | ::4.3.0.13/24
|
2006-02-11 04:32:41 +01:00
|
|
|
(17 rows)
|
|
|
|
|
2006-02-11 21:39:59 +01:00
|
|
|
SELECT i, c, i - c AS "minus" FROM inet_tbl;
|
|
|
|
i | c | minus
|
|
|
|
------------------+--------------------+------------------
|
|
|
|
192.168.1.226/24 | 192.168.1.0/24 | 226
|
|
|
|
192.168.1.226 | 192.168.1.0/26 | 226
|
|
|
|
192.168.1.0/24 | 192.168.1.0/24 | 0
|
|
|
|
192.168.1.0/25 | 192.168.1.0/24 | 0
|
|
|
|
192.168.1.255/24 | 192.168.1.0/24 | 255
|
|
|
|
192.168.1.255/25 | 192.168.1.0/24 | 255
|
|
|
|
10.1.2.3/8 | 10.0.0.0/8 | 66051
|
|
|
|
10.1.2.3/8 | 10.0.0.0/32 | 66051
|
|
|
|
10.1.2.3 | 10.1.2.3/32 | 0
|
|
|
|
10.1.2.3/24 | 10.1.2.0/24 | 3
|
|
|
|
10.1.2.3/16 | 10.1.0.0/16 | 515
|
|
|
|
10.1.2.3/8 | 10.0.0.0/8 | 66051
|
|
|
|
11.1.2.3/8 | 10.0.0.0/8 | 16843267
|
|
|
|
9.1.2.3/8 | 10.0.0.0/8 | -16711165
|
|
|
|
10:23::f1/64 | 10:23::f1/128 | 0
|
|
|
|
10:23::ffff | 10:23::8000/113 | 32767
|
|
|
|
::4.3.2.1/24 | ::ffff:1.2.3.4/128 | -281470631346435
|
|
|
|
(17 rows)
|
|
|
|
|
|
|
|
SELECT '127.0.0.1'::inet + 257;
|
|
|
|
?column?
|
|
|
|
-----------
|
|
|
|
127.0.1.2
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT ('127.0.0.1'::inet + 257) - 257;
|
2006-02-11 04:32:41 +01:00
|
|
|
?column?
|
2006-02-11 21:39:59 +01:00
|
|
|
-----------
|
|
|
|
127.0.0.1
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT '127::1'::inet + 257;
|
|
|
|
?column?
|
|
|
|
----------
|
|
|
|
127::102
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT ('127::1'::inet + 257) - 257;
|
|
|
|
?column?
|
|
|
|
----------
|
2006-02-12 04:10:04 +01:00
|
|
|
127::1
|
2006-02-11 21:39:59 +01:00
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT '127.0.0.2'::inet - ('127.0.0.2'::inet + 500);
|
|
|
|
?column?
|
|
|
|
----------
|
|
|
|
-500
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT '127.0.0.2'::inet - ('127.0.0.2'::inet - 500);
|
|
|
|
?column?
|
|
|
|
----------
|
|
|
|
500
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT '127::2'::inet - ('127::2'::inet + 500);
|
|
|
|
?column?
|
|
|
|
----------
|
|
|
|
-500
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT '127::2'::inet - ('127::2'::inet - 500);
|
|
|
|
?column?
|
|
|
|
----------
|
|
|
|
500
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
-- these should give overflow errors:
|
|
|
|
SELECT '127.0.0.1'::inet + 10000000000;
|
2007-01-03 00:38:42 +01:00
|
|
|
ERROR: result is out of range
|
2006-02-11 21:39:59 +01:00
|
|
|
SELECT '127.0.0.1'::inet - 10000000000;
|
2007-01-03 00:38:42 +01:00
|
|
|
ERROR: result is out of range
|
2006-02-11 21:39:59 +01:00
|
|
|
SELECT '126::1'::inet - '127::2'::inet;
|
2007-01-03 00:38:42 +01:00
|
|
|
ERROR: result is out of range
|
2006-02-11 21:39:59 +01:00
|
|
|
SELECT '127::1'::inet - '126::2'::inet;
|
2007-01-03 00:38:42 +01:00
|
|
|
ERROR: result is out of range
|
2006-02-11 21:39:59 +01:00
|
|
|
-- but not these
|
|
|
|
SELECT '127::1'::inet + 10000000000;
|
|
|
|
?column?
|
2006-02-11 04:32:41 +01:00
|
|
|
------------------
|
2006-02-11 21:39:59 +01:00
|
|
|
127::2:540b:e401
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT '127::1'::inet - '127::2'::inet;
|
|
|
|
?column?
|
|
|
|
----------
|
|
|
|
-1
|
|
|
|
(1 row)
|
2006-02-11 04:32:41 +01:00
|
|
|
|
2015-05-05 20:22:24 +02:00
|
|
|
-- insert one more row with addressed from different families
|
|
|
|
INSERT INTO INET_TBL (c, i) VALUES ('10', '10::/8');
|
|
|
|
-- now, this one should fail
|
|
|
|
SELECT inet_merge(c, i) FROM INET_TBL;
|
|
|
|
ERROR: cannot merge addresses from different families
|
|
|
|
-- fix it by inet_same_family() condition
|
|
|
|
SELECT inet_merge(c, i) FROM INET_TBL WHERE inet_same_family(c, i);
|
|
|
|
inet_merge
|
|
|
|
-----------------
|
|
|
|
192.168.1.0/24
|
|
|
|
192.168.1.0/24
|
|
|
|
192.168.1.0/24
|
|
|
|
192.168.1.0/24
|
|
|
|
192.168.1.0/24
|
|
|
|
192.168.1.0/24
|
|
|
|
10.0.0.0/8
|
|
|
|
10.0.0.0/8
|
|
|
|
10.1.2.3/32
|
|
|
|
10.1.2.0/24
|
|
|
|
10.1.0.0/16
|
|
|
|
10.0.0.0/8
|
|
|
|
10.0.0.0/7
|
|
|
|
8.0.0.0/6
|
|
|
|
10:23::/64
|
|
|
|
10:23::8000/113
|
|
|
|
::/24
|
|
|
|
(17 rows)
|
|
|
|
|
2019-08-01 18:34:14 +02:00
|
|
|
-- Test inet sortsupport with a variety of boundary inputs:
|
|
|
|
SELECT a FROM (VALUES
|
|
|
|
('0.0.0.0/0'::inet),
|
|
|
|
('0.0.0.0/1'::inet),
|
|
|
|
('0.0.0.0/32'::inet),
|
|
|
|
('0.0.0.1/0'::inet),
|
|
|
|
('0.0.0.1/1'::inet),
|
|
|
|
('127.126.127.127/0'::inet),
|
|
|
|
('127.127.127.127/0'::inet),
|
|
|
|
('127.128.127.127/0'::inet),
|
|
|
|
('192.168.1.0/24'::inet),
|
|
|
|
('192.168.1.0/25'::inet),
|
|
|
|
('192.168.1.1/23'::inet),
|
|
|
|
('192.168.1.1/5'::inet),
|
|
|
|
('192.168.1.1/6'::inet),
|
|
|
|
('192.168.1.1/25'::inet),
|
|
|
|
('192.168.1.2/25'::inet),
|
|
|
|
('192.168.1.1/26'::inet),
|
|
|
|
('192.168.1.2/26'::inet),
|
|
|
|
('192.168.1.2/23'::inet),
|
|
|
|
('192.168.1.255/5'::inet),
|
|
|
|
('192.168.1.255/6'::inet),
|
|
|
|
('192.168.1.3/1'::inet),
|
|
|
|
('192.168.1.3/23'::inet),
|
|
|
|
('192.168.1.4/0'::inet),
|
|
|
|
('192.168.1.5/0'::inet),
|
|
|
|
('255.0.0.0/0'::inet),
|
|
|
|
('255.1.0.0/0'::inet),
|
|
|
|
('255.2.0.0/0'::inet),
|
|
|
|
('255.255.000.000/0'::inet),
|
|
|
|
('255.255.000.000/0'::inet),
|
|
|
|
('255.255.000.000/15'::inet),
|
|
|
|
('255.255.000.000/16'::inet),
|
|
|
|
('255.255.255.254/32'::inet),
|
|
|
|
('255.255.255.000/32'::inet),
|
|
|
|
('255.255.255.001/31'::inet),
|
|
|
|
('255.255.255.002/31'::inet),
|
|
|
|
('255.255.255.003/31'::inet),
|
|
|
|
('255.255.255.003/32'::inet),
|
|
|
|
('255.255.255.001/32'::inet),
|
|
|
|
('255.255.255.255/0'::inet),
|
|
|
|
('255.255.255.255/0'::inet),
|
|
|
|
('255.255.255.255/0'::inet),
|
|
|
|
('255.255.255.255/1'::inet),
|
|
|
|
('255.255.255.255/16'::inet),
|
|
|
|
('255.255.255.255/16'::inet),
|
|
|
|
('255.255.255.255/31'::inet),
|
|
|
|
('255.255.255.255/32'::inet),
|
|
|
|
('255.255.255.253/32'::inet),
|
|
|
|
('255.255.255.252/32'::inet),
|
|
|
|
('255.3.0.0/0'::inet),
|
|
|
|
('0000:0000:0000:0000:0000:0000:0000:0000/0'::inet),
|
|
|
|
('0000:0000:0000:0000:0000:0000:0000:0000/128'::inet),
|
|
|
|
('0000:0000:0000:0000:0000:0000:0000:0001/128'::inet),
|
|
|
|
('10:23::f1/64'::inet),
|
|
|
|
('10:23::f1/65'::inet),
|
|
|
|
('10:23::ffff'::inet),
|
|
|
|
('127::1'::inet),
|
|
|
|
('127::2'::inet),
|
|
|
|
('8000:0000:0000:0000:0000:0000:0000:0000/1'::inet),
|
|
|
|
('::1:ffff:ffff:ffff:ffff/128'::inet),
|
|
|
|
('::2:ffff:ffff:ffff:ffff/128'::inet),
|
|
|
|
('::4:3:2:0/24'::inet),
|
|
|
|
('::4:3:2:1/24'::inet),
|
|
|
|
('::4:3:2:2/24'::inet),
|
|
|
|
('ffff:83e7:f118:57dc:6093:6d92:689d:58cf/70'::inet),
|
|
|
|
('ffff:84b0:4775:536e:c3ed:7116:a6d6:34f0/44'::inet),
|
|
|
|
('ffff:8566:f84:5867:47f1:7867:d2ba:8a1a/69'::inet),
|
|
|
|
('ffff:8883:f028:7d2:4d68:d510:7d6b:ac43/73'::inet),
|
|
|
|
('ffff:8ae8:7c14:65b3:196:8e4a:89ae:fb30/89'::inet),
|
|
|
|
('ffff:8dd0:646:694c:7c16:7e35:6a26:171/104'::inet),
|
|
|
|
('ffff:8eef:cbf:700:eda3:ae32:f4b4:318b/121'::inet),
|
|
|
|
('ffff:90e7:e744:664:a93:8efe:1f25:7663/122'::inet),
|
|
|
|
('ffff:9597:c69c:8b24:57a:8639:ec78:6026/111'::inet),
|
|
|
|
('ffff:9e86:79ea:f16e:df31:8e4d:7783:532e/88'::inet),
|
|
|
|
('ffff:a0c7:82d3:24de:f762:6e1f:316d:3fb2/23'::inet),
|
|
|
|
('ffff:fffa:ffff:ffff:ffff:ffff:ffff:ffff/0'::inet),
|
|
|
|
('ffff:fffb:ffff:ffff:ffff:ffff:ffff:ffff/0'::inet),
|
|
|
|
('ffff:fffc:ffff:ffff:ffff:ffff:ffff:ffff/0'::inet),
|
|
|
|
('ffff:fffd:ffff:ffff:ffff:ffff:ffff:ffff/0'::inet),
|
|
|
|
('ffff:fffe:ffff:ffff:ffff:ffff:ffff:ffff/0'::inet),
|
|
|
|
('ffff:ffff:ffff:fffa:ffff:ffff:ffff:ffff/0'::inet),
|
|
|
|
('ffff:ffff:ffff:fffb:ffff:ffff:ffff:ffff/0'::inet),
|
|
|
|
('ffff:ffff:ffff:fffc:ffff:ffff:ffff:ffff/0'::inet),
|
|
|
|
('ffff:ffff:ffff:fffd::/128'::inet),
|
|
|
|
('ffff:ffff:ffff:fffd:ffff:ffff:ffff:ffff/0'::inet),
|
|
|
|
('ffff:ffff:ffff:fffe::/128'::inet),
|
|
|
|
('ffff:ffff:ffff:fffe:ffff:ffff:ffff:ffff/0'::inet),
|
|
|
|
('ffff:ffff:ffff:ffff:4:3:2:0/24'::inet),
|
|
|
|
('ffff:ffff:ffff:ffff:4:3:2:1/24'::inet),
|
|
|
|
('ffff:ffff:ffff:ffff:4:3:2:2/24'::inet),
|
|
|
|
('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/0'::inet),
|
|
|
|
('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128'::inet)
|
|
|
|
) AS i(a) ORDER BY a;
|
|
|
|
a
|
|
|
|
--------------------------------------------
|
|
|
|
0.0.0.0/0
|
|
|
|
0.0.0.1/0
|
|
|
|
127.126.127.127/0
|
|
|
|
127.127.127.127/0
|
|
|
|
127.128.127.127/0
|
|
|
|
192.168.1.4/0
|
|
|
|
192.168.1.5/0
|
|
|
|
255.0.0.0/0
|
|
|
|
255.1.0.0/0
|
|
|
|
255.2.0.0/0
|
|
|
|
255.3.0.0/0
|
|
|
|
255.255.0.0/0
|
|
|
|
255.255.0.0/0
|
|
|
|
255.255.255.255/0
|
|
|
|
255.255.255.255/0
|
|
|
|
255.255.255.255/0
|
|
|
|
0.0.0.0/1
|
|
|
|
0.0.0.1/1
|
|
|
|
0.0.0.0
|
|
|
|
192.168.1.3/1
|
|
|
|
255.255.255.255/1
|
|
|
|
192.168.1.1/5
|
|
|
|
192.168.1.255/5
|
|
|
|
192.168.1.1/6
|
|
|
|
192.168.1.255/6
|
|
|
|
192.168.1.1/23
|
|
|
|
192.168.1.2/23
|
|
|
|
192.168.1.3/23
|
|
|
|
192.168.1.0/24
|
|
|
|
192.168.1.0/25
|
|
|
|
192.168.1.1/25
|
|
|
|
192.168.1.2/25
|
|
|
|
192.168.1.1/26
|
|
|
|
192.168.1.2/26
|
|
|
|
255.255.0.0/15
|
|
|
|
255.255.0.0/16
|
|
|
|
255.255.255.255/16
|
|
|
|
255.255.255.255/16
|
|
|
|
255.255.255.1/31
|
|
|
|
255.255.255.0
|
|
|
|
255.255.255.1
|
|
|
|
255.255.255.2/31
|
|
|
|
255.255.255.3/31
|
|
|
|
255.255.255.3
|
|
|
|
255.255.255.252
|
|
|
|
255.255.255.253
|
|
|
|
255.255.255.255/31
|
|
|
|
255.255.255.254
|
|
|
|
255.255.255.255
|
|
|
|
::/0
|
|
|
|
ffff:fffa:ffff:ffff:ffff:ffff:ffff:ffff/0
|
|
|
|
ffff:fffb:ffff:ffff:ffff:ffff:ffff:ffff/0
|
|
|
|
ffff:fffc:ffff:ffff:ffff:ffff:ffff:ffff/0
|
|
|
|
ffff:fffd:ffff:ffff:ffff:ffff:ffff:ffff/0
|
|
|
|
ffff:fffe:ffff:ffff:ffff:ffff:ffff:ffff/0
|
|
|
|
ffff:ffff:ffff:fffa:ffff:ffff:ffff:ffff/0
|
|
|
|
ffff:ffff:ffff:fffb:ffff:ffff:ffff:ffff/0
|
|
|
|
ffff:ffff:ffff:fffc:ffff:ffff:ffff:ffff/0
|
|
|
|
ffff:ffff:ffff:fffd:ffff:ffff:ffff:ffff/0
|
|
|
|
ffff:ffff:ffff:fffe:ffff:ffff:ffff:ffff/0
|
|
|
|
ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/0
|
|
|
|
::4:3:2:0/24
|
|
|
|
::4:3:2:1/24
|
|
|
|
::4:3:2:2/24
|
|
|
|
::
|
|
|
|
::1
|
|
|
|
::1:ffff:ffff:ffff:ffff
|
|
|
|
::2:ffff:ffff:ffff:ffff
|
|
|
|
10:23::f1/64
|
|
|
|
10:23::f1/65
|
|
|
|
10:23::ffff
|
|
|
|
127::1
|
|
|
|
127::2
|
|
|
|
8000::/1
|
|
|
|
ffff:83e7:f118:57dc:6093:6d92:689d:58cf/70
|
|
|
|
ffff:84b0:4775:536e:c3ed:7116:a6d6:34f0/44
|
|
|
|
ffff:8566:f84:5867:47f1:7867:d2ba:8a1a/69
|
|
|
|
ffff:8883:f028:7d2:4d68:d510:7d6b:ac43/73
|
|
|
|
ffff:8ae8:7c14:65b3:196:8e4a:89ae:fb30/89
|
|
|
|
ffff:8dd0:646:694c:7c16:7e35:6a26:171/104
|
|
|
|
ffff:8eef:cbf:700:eda3:ae32:f4b4:318b/121
|
|
|
|
ffff:90e7:e744:664:a93:8efe:1f25:7663/122
|
|
|
|
ffff:9597:c69c:8b24:57a:8639:ec78:6026/111
|
|
|
|
ffff:9e86:79ea:f16e:df31:8e4d:7783:532e/88
|
|
|
|
ffff:a0c7:82d3:24de:f762:6e1f:316d:3fb2/23
|
|
|
|
ffff:ffff:ffff:ffff:4:3:2:0/24
|
|
|
|
ffff:ffff:ffff:ffff:4:3:2:1/24
|
|
|
|
ffff:ffff:ffff:ffff:4:3:2:2/24
|
|
|
|
ffff:ffff:ffff:fffd::
|
|
|
|
ffff:ffff:ffff:fffe::
|
|
|
|
ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff
|
|
|
|
(91 rows)
|
|
|
|
|
2022-12-14 19:22:08 +01:00
|
|
|
-- test non-error-throwing API for some core types
|
|
|
|
SELECT pg_input_is_valid('1234', 'cidr');
|
|
|
|
pg_input_is_valid
|
|
|
|
-------------------
|
|
|
|
f
|
|
|
|
(1 row)
|
|
|
|
|
2023-02-28 00:04:13 +01:00
|
|
|
SELECT * FROM pg_input_error_info('1234', 'cidr');
|
|
|
|
message | detail | hint | sql_error_code
|
|
|
|
--------------------------------------------+--------+------+----------------
|
|
|
|
invalid input syntax for type cidr: "1234" | | | 22P02
|
2022-12-14 19:22:08 +01:00
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT pg_input_is_valid('192.168.198.200/24', 'cidr');
|
|
|
|
pg_input_is_valid
|
|
|
|
-------------------
|
|
|
|
f
|
|
|
|
(1 row)
|
|
|
|
|
2023-02-28 00:04:13 +01:00
|
|
|
SELECT * FROM pg_input_error_info('192.168.198.200/24', 'cidr');
|
|
|
|
message | detail | hint | sql_error_code
|
|
|
|
------------------------------------------+--------------------------------------+------+----------------
|
|
|
|
invalid cidr value: "192.168.198.200/24" | Value has bits set to right of mask. | | 22P02
|
2022-12-14 19:22:08 +01:00
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT pg_input_is_valid('1234', 'inet');
|
|
|
|
pg_input_is_valid
|
|
|
|
-------------------
|
|
|
|
f
|
|
|
|
(1 row)
|
|
|
|
|
2023-02-28 00:04:13 +01:00
|
|
|
SELECT * FROM pg_input_error_info('1234', 'inet');
|
|
|
|
message | detail | hint | sql_error_code
|
|
|
|
--------------------------------------------+--------+------+----------------
|
|
|
|
invalid input syntax for type inet: "1234" | | | 22P02
|
2022-12-14 19:22:08 +01:00
|
|
|
(1 row)
|
|
|
|
|