4 -- prepare the table...
6 ERROR: table "inet_tbl" does not exist
7 CREATE TABLE INET_TBL (c cidr, i inet);
8 INSERT INTO INET_TBL (c, i) VALUES ('192.168.1', '192.168.1.226/24');
9 INSERT INTO INET_TBL (c, i) VALUES ('192.168.1.0/26', '192.168.1.226');
10 INSERT INTO INET_TBL (c, i) VALUES ('192.168.1', '192.168.1.0/24');
11 INSERT INTO INET_TBL (c, i) VALUES ('192.168.1', '192.168.1.0/25');
12 INSERT INTO INET_TBL (c, i) VALUES ('192.168.1', '192.168.1.255/24');
13 INSERT INTO INET_TBL (c, i) VALUES ('192.168.1', '192.168.1.255/25');
14 INSERT INTO INET_TBL (c, i) VALUES ('10', '10.1.2.3/8');
15 INSERT INTO INET_TBL (c, i) VALUES ('10.0.0.0', '10.1.2.3/8');
16 INSERT INTO INET_TBL (c, i) VALUES ('10.1.2.3', '10.1.2.3/32');
17 INSERT INTO INET_TBL (c, i) VALUES ('10.1.2', '10.1.2.3/24');
18 INSERT INTO INET_TBL (c, i) VALUES ('10.1', '10.1.2.3/16');
19 INSERT INTO INET_TBL (c, i) VALUES ('10', '10.1.2.3/8');
20 INSERT INTO INET_TBL (c, i) VALUES ('10', '11.1.2.3/8');
21 INSERT INTO INET_TBL (c, i) VALUES ('10', '9.1.2.3/8');
22 INSERT INTO INET_TBL (c, i) VALUES ('10:23::f1', '10:23::f1/64');
23 INSERT INTO INET_TBL (c, i) VALUES ('10:23::8000/113', '10:23::ffff');
24 INSERT INTO INET_TBL (c, i) VALUES ('::ffff:1.2.3.4', '::4.3.2.1/24');
25 -- check that CIDR rejects invalid input:
26 INSERT INTO INET_TBL (c, i) VALUES ('192.168.1.2/30', '192.168.1.226');
27 ERROR: invalid cidr value: "192.168.1.2/30"
28 LINE 1: INSERT INTO INET_TBL (c, i) VALUES ('192.168.1.2/30', '192.1...
30 DETAIL: Value has bits set to right of mask.
31 INSERT INTO INET_TBL (c, i) VALUES ('1234::1234::1234', '::1.2.3.4');
32 ERROR: invalid input syntax for type cidr: "1234::1234::1234"
33 LINE 1: INSERT INTO INET_TBL (c, i) VALUES ('1234::1234::1234', '::1...
35 -- check that CIDR rejects invalid input when converting from text:
36 INSERT INTO INET_TBL (c, i) VALUES (cidr('192.168.1.2/30'), '192.168.1.226');
37 ERROR: invalid cidr value: "192.168.1.2/30"
38 LINE 1: INSERT INTO INET_TBL (c, i) VALUES (cidr('192.168.1.2/30'), ...
40 DETAIL: Value has bits set to right of mask.
41 INSERT INTO INET_TBL (c, i) VALUES (cidr('ffff:ffff:ffff:ffff::/24'), '::192.168.1.226');
42 ERROR: invalid cidr value: "ffff:ffff:ffff:ffff::/24"
43 LINE 1: INSERT INTO INET_TBL (c, i) VALUES (cidr('ffff:ffff:ffff:fff...
45 DETAIL: Value has bits set to right of mask.
46 SELECT '' AS ten, c AS cidr, i AS inet FROM INET_TBL;
48 -----+--------------------+------------------
49 | 192.168.1.0/24 | 192.168.1.226/24
50 | 192.168.1.0/26 | 192.168.1.226
51 | 192.168.1.0/24 | 192.168.1.0/24
52 | 192.168.1.0/24 | 192.168.1.0/25
53 | 192.168.1.0/24 | 192.168.1.255/24
54 | 192.168.1.0/24 | 192.168.1.255/25
55 | 10.0.0.0/8 | 10.1.2.3/8
56 | 10.0.0.0/32 | 10.1.2.3/8
57 | 10.1.2.3/32 | 10.1.2.3
58 | 10.1.2.0/24 | 10.1.2.3/24
59 | 10.1.0.0/16 | 10.1.2.3/16
60 | 10.0.0.0/8 | 10.1.2.3/8
61 | 10.0.0.0/8 | 11.1.2.3/8
62 | 10.0.0.0/8 | 9.1.2.3/8
63 | 10:23::f1/128 | 10:23::f1/64
64 | 10:23::8000/113 | 10:23::ffff
65 | ::ffff:1.2.3.4/128 | ::4.3.2.1/24
68 -- now test some support functions
69 SELECT '' AS ten, i AS inet, host(i), text(i), family(i) FROM INET_TBL;
70 ten | inet | host | text | family
71 -----+------------------+---------------+------------------+--------
72 | 192.168.1.226/24 | 192.168.1.226 | 192.168.1.226/24 | 4
73 | 192.168.1.226 | 192.168.1.226 | 192.168.1.226/32 | 4
74 | 192.168.1.0/24 | 192.168.1.0 | 192.168.1.0/24 | 4
75 | 192.168.1.0/25 | 192.168.1.0 | 192.168.1.0/25 | 4
76 | 192.168.1.255/24 | 192.168.1.255 | 192.168.1.255/24 | 4
77 | 192.168.1.255/25 | 192.168.1.255 | 192.168.1.255/25 | 4
78 | 10.1.2.3/8 | 10.1.2.3 | 10.1.2.3/8 | 4
79 | 10.1.2.3/8 | 10.1.2.3 | 10.1.2.3/8 | 4
80 | 10.1.2.3 | 10.1.2.3 | 10.1.2.3/32 | 4
81 | 10.1.2.3/24 | 10.1.2.3 | 10.1.2.3/24 | 4
82 | 10.1.2.3/16 | 10.1.2.3 | 10.1.2.3/16 | 4
83 | 10.1.2.3/8 | 10.1.2.3 | 10.1.2.3/8 | 4
84 | 11.1.2.3/8 | 11.1.2.3 | 11.1.2.3/8 | 4
85 | 9.1.2.3/8 | 9.1.2.3 | 9.1.2.3/8 | 4
86 | 10:23::f1/64 | 10:23::f1 | 10:23::f1/64 | 6
87 | 10:23::ffff | 10:23::ffff | 10:23::ffff/128 | 6
88 | ::4.3.2.1/24 | ::4.3.2.1 | ::4.3.2.1/24 | 6
91 SELECT '' AS ten, c AS cidr, broadcast(c),
92 i AS inet, broadcast(i) FROM INET_TBL;
93 ten | cidr | broadcast | inet | broadcast
94 -----+--------------------+------------------+------------------+---------------------------------------
95 | 192.168.1.0/24 | 192.168.1.255/24 | 192.168.1.226/24 | 192.168.1.255/24
96 | 192.168.1.0/26 | 192.168.1.63/26 | 192.168.1.226 | 192.168.1.226
97 | 192.168.1.0/24 | 192.168.1.255/24 | 192.168.1.0/24 | 192.168.1.255/24
98 | 192.168.1.0/24 | 192.168.1.255/24 | 192.168.1.0/25 | 192.168.1.127/25
99 | 192.168.1.0/24 | 192.168.1.255/24 | 192.168.1.255/24 | 192.168.1.255/24
100 | 192.168.1.0/24 | 192.168.1.255/24 | 192.168.1.255/25 | 192.168.1.255/25
101 | 10.0.0.0/8 | 10.255.255.255/8 | 10.1.2.3/8 | 10.255.255.255/8
102 | 10.0.0.0/32 | 10.0.0.0 | 10.1.2.3/8 | 10.255.255.255/8
103 | 10.1.2.3/32 | 10.1.2.3 | 10.1.2.3 | 10.1.2.3
104 | 10.1.2.0/24 | 10.1.2.255/24 | 10.1.2.3/24 | 10.1.2.255/24
105 | 10.1.0.0/16 | 10.1.255.255/16 | 10.1.2.3/16 | 10.1.255.255/16
106 | 10.0.0.0/8 | 10.255.255.255/8 | 10.1.2.3/8 | 10.255.255.255/8
107 | 10.0.0.0/8 | 10.255.255.255/8 | 11.1.2.3/8 | 11.255.255.255/8
108 | 10.0.0.0/8 | 10.255.255.255/8 | 9.1.2.3/8 | 9.255.255.255/8
109 | 10:23::f1/128 | 10:23::f1 | 10:23::f1/64 | 10:23::ffff:ffff:ffff:ffff/64
110 | 10:23::8000/113 | 10:23::ffff/113 | 10:23::ffff | 10:23::ffff
111 | ::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
114 SELECT '' AS ten, c AS cidr, network(c) AS "network(cidr)",
115 i AS inet, network(i) AS "network(inet)" FROM INET_TBL;
116 ten | cidr | network(cidr) | inet | network(inet)
117 -----+--------------------+--------------------+------------------+------------------
118 | 192.168.1.0/24 | 192.168.1.0/24 | 192.168.1.226/24 | 192.168.1.0/24
119 | 192.168.1.0/26 | 192.168.1.0/26 | 192.168.1.226 | 192.168.1.226/32
120 | 192.168.1.0/24 | 192.168.1.0/24 | 192.168.1.0/24 | 192.168.1.0/24
121 | 192.168.1.0/24 | 192.168.1.0/24 | 192.168.1.0/25 | 192.168.1.0/25
122 | 192.168.1.0/24 | 192.168.1.0/24 | 192.168.1.255/24 | 192.168.1.0/24
123 | 192.168.1.0/24 | 192.168.1.0/24 | 192.168.1.255/25 | 192.168.1.128/25
124 | 10.0.0.0/8 | 10.0.0.0/8 | 10.1.2.3/8 | 10.0.0.0/8
125 | 10.0.0.0/32 | 10.0.0.0/32 | 10.1.2.3/8 | 10.0.0.0/8
126 | 10.1.2.3/32 | 10.1.2.3/32 | 10.1.2.3 | 10.1.2.3/32
127 | 10.1.2.0/24 | 10.1.2.0/24 | 10.1.2.3/24 | 10.1.2.0/24
128 | 10.1.0.0/16 | 10.1.0.0/16 | 10.1.2.3/16 | 10.1.0.0/16
129 | 10.0.0.0/8 | 10.0.0.0/8 | 10.1.2.3/8 | 10.0.0.0/8
130 | 10.0.0.0/8 | 10.0.0.0/8 | 11.1.2.3/8 | 11.0.0.0/8
131 | 10.0.0.0/8 | 10.0.0.0/8 | 9.1.2.3/8 | 9.0.0.0/8
132 | 10:23::f1/128 | 10:23::f1/128 | 10:23::f1/64 | 10:23::/64
133 | 10:23::8000/113 | 10:23::8000/113 | 10:23::ffff | 10:23::ffff/128
134 | ::ffff:1.2.3.4/128 | ::ffff:1.2.3.4/128 | ::4.3.2.1/24 | ::/24
137 SELECT '' AS ten, c AS cidr, masklen(c) AS "masklen(cidr)",
138 i AS inet, masklen(i) AS "masklen(inet)" FROM INET_TBL;
139 ten | cidr | masklen(cidr) | inet | masklen(inet)
140 -----+--------------------+---------------+------------------+---------------
141 | 192.168.1.0/24 | 24 | 192.168.1.226/24 | 24
142 | 192.168.1.0/26 | 26 | 192.168.1.226 | 32
143 | 192.168.1.0/24 | 24 | 192.168.1.0/24 | 24
144 | 192.168.1.0/24 | 24 | 192.168.1.0/25 | 25
145 | 192.168.1.0/24 | 24 | 192.168.1.255/24 | 24
146 | 192.168.1.0/24 | 24 | 192.168.1.255/25 | 25
147 | 10.0.0.0/8 | 8 | 10.1.2.3/8 | 8
148 | 10.0.0.0/32 | 32 | 10.1.2.3/8 | 8
149 | 10.1.2.3/32 | 32 | 10.1.2.3 | 32
150 | 10.1.2.0/24 | 24 | 10.1.2.3/24 | 24
151 | 10.1.0.0/16 | 16 | 10.1.2.3/16 | 16
152 | 10.0.0.0/8 | 8 | 10.1.2.3/8 | 8
153 | 10.0.0.0/8 | 8 | 11.1.2.3/8 | 8
154 | 10.0.0.0/8 | 8 | 9.1.2.3/8 | 8
155 | 10:23::f1/128 | 128 | 10:23::f1/64 | 64
156 | 10:23::8000/113 | 113 | 10:23::ffff | 128
157 | ::ffff:1.2.3.4/128 | 128 | ::4.3.2.1/24 | 24
160 SELECT '' AS four, c AS cidr, masklen(c) AS "masklen(cidr)",
161 i AS inet, masklen(i) AS "masklen(inet)" FROM INET_TBL
162 WHERE masklen(c) <= 8;
163 four | cidr | masklen(cidr) | inet | masklen(inet)
164 ------+------------+---------------+------------+---------------
165 | 10.0.0.0/8 | 8 | 10.1.2.3/8 | 8
166 | 10.0.0.0/8 | 8 | 10.1.2.3/8 | 8
167 | 10.0.0.0/8 | 8 | 11.1.2.3/8 | 8
168 | 10.0.0.0/8 | 8 | 9.1.2.3/8 | 8
171 SELECT '' AS six, c AS cidr, i AS inet FROM INET_TBL
174 -----+----------------+----------------
175 | 192.168.1.0/24 | 192.168.1.0/24
176 | 10.1.2.3/32 | 10.1.2.3
179 SELECT '' AS ten, i, c,
180 i < c AS lt, i <= c AS le, i = c AS eq,
181 i >= c AS ge, i > c AS gt, i <> c AS ne,
182 i << c AS sb, i <<= c AS sbe,
183 i >> c AS sup, i >>= c AS spe
185 ten | i | c | lt | le | eq | ge | gt | ne | sb | sbe | sup | spe
186 -----+------------------+--------------------+----+----+----+----+----+----+----+-----+-----+-----
187 | 192.168.1.226/24 | 192.168.1.0/24 | f | f | f | t | t | t | f | t | f | t
188 | 192.168.1.226 | 192.168.1.0/26 | f | f | f | t | t | t | f | f | f | f
189 | 192.168.1.0/24 | 192.168.1.0/24 | f | t | t | t | f | f | f | t | f | t
190 | 192.168.1.0/25 | 192.168.1.0/24 | f | f | f | t | t | t | t | t | f | f
191 | 192.168.1.255/24 | 192.168.1.0/24 | f | f | f | t | t | t | f | t | f | t
192 | 192.168.1.255/25 | 192.168.1.0/24 | f | f | f | t | t | t | t | t | f | f
193 | 10.1.2.3/8 | 10.0.0.0/8 | f | f | f | t | t | t | f | t | f | t
194 | 10.1.2.3/8 | 10.0.0.0/32 | t | t | f | f | f | t | f | f | t | t
195 | 10.1.2.3 | 10.1.2.3/32 | f | t | t | t | f | f | f | t | f | t
196 | 10.1.2.3/24 | 10.1.2.0/24 | f | f | f | t | t | t | f | t | f | t
197 | 10.1.2.3/16 | 10.1.0.0/16 | f | f | f | t | t | t | f | t | f | t
198 | 10.1.2.3/8 | 10.0.0.0/8 | f | f | f | t | t | t | f | t | f | t
199 | 11.1.2.3/8 | 10.0.0.0/8 | f | f | f | t | t | t | f | f | f | f
200 | 9.1.2.3/8 | 10.0.0.0/8 | t | t | f | f | f | t | f | f | f | f
201 | 10:23::f1/64 | 10:23::f1/128 | t | t | f | f | f | t | f | f | t | t
202 | 10:23::ffff | 10:23::8000/113 | f | f | f | t | t | t | t | t | f | f
203 | ::4.3.2.1/24 | ::ffff:1.2.3.4/128 | t | t | f | f | f | t | f | f | t | t
206 -- check the conversion to/from text and set_netmask
207 SELECT '' AS ten, set_masklen(inet(text(i)), 24) FROM INET_TBL;
209 -----+------------------
229 -- check that index works correctly
230 CREATE INDEX inet_idx1 ON inet_tbl(i);
231 SET enable_seqscan TO off;
232 SELECT * FROM inet_tbl WHERE i<<'192.168.1.0/24'::cidr;
234 ----------------+------------------
235 192.168.1.0/24 | 192.168.1.0/25
236 192.168.1.0/24 | 192.168.1.255/25
237 192.168.1.0/26 | 192.168.1.226
240 SELECT * FROM inet_tbl WHERE i<<='192.168.1.0/24'::cidr;
242 ----------------+------------------
243 192.168.1.0/24 | 192.168.1.0/24
244 192.168.1.0/24 | 192.168.1.226/24
245 192.168.1.0/24 | 192.168.1.255/24
246 192.168.1.0/24 | 192.168.1.0/25
247 192.168.1.0/24 | 192.168.1.255/25
248 192.168.1.0/26 | 192.168.1.226
251 SET enable_seqscan TO on;
252 DROP INDEX inet_idx1;
253 -- simple tests of inet boolean and arithmetic operators
254 SELECT i, ~i AS "~i" FROM inet_tbl;
256 ------------------+--------------------------------------------
257 192.168.1.226/24 | 63.87.254.29/24
258 192.168.1.226 | 63.87.254.29
259 192.168.1.0/24 | 63.87.254.255/24
260 192.168.1.0/25 | 63.87.254.255/25
261 192.168.1.255/24 | 63.87.254.0/24
262 192.168.1.255/25 | 63.87.254.0/25
263 10.1.2.3/8 | 245.254.253.252/8
264 10.1.2.3/8 | 245.254.253.252/8
265 10.1.2.3 | 245.254.253.252
266 10.1.2.3/24 | 245.254.253.252/24
267 10.1.2.3/16 | 245.254.253.252/16
268 10.1.2.3/8 | 245.254.253.252/8
269 11.1.2.3/8 | 244.254.253.252/8
270 9.1.2.3/8 | 246.254.253.252/8
271 10:23::f1/64 | ffef:ffdc:ffff:ffff:ffff:ffff:ffff:ff0e/64
272 10:23::ffff | ffef:ffdc:ffff:ffff:ffff:ffff:ffff:0
273 ::4.3.2.1/24 | ffff:ffff:ffff:ffff:ffff:ffff:fbfc:fdfe/24
276 SELECT i, c, i & c AS "and" FROM inet_tbl;
278 ------------------+--------------------+----------------
279 192.168.1.226/24 | 192.168.1.0/24 | 192.168.1.0/24
280 192.168.1.226 | 192.168.1.0/26 | 192.168.1.0
281 192.168.1.0/24 | 192.168.1.0/24 | 192.168.1.0/24
282 192.168.1.0/25 | 192.168.1.0/24 | 192.168.1.0/25
283 192.168.1.255/24 | 192.168.1.0/24 | 192.168.1.0/24
284 192.168.1.255/25 | 192.168.1.0/24 | 192.168.1.0/25
285 10.1.2.3/8 | 10.0.0.0/8 | 10.0.0.0/8
286 10.1.2.3/8 | 10.0.0.0/32 | 10.0.0.0
287 10.1.2.3 | 10.1.2.3/32 | 10.1.2.3
288 10.1.2.3/24 | 10.1.2.0/24 | 10.1.2.0/24
289 10.1.2.3/16 | 10.1.0.0/16 | 10.1.0.0/16
290 10.1.2.3/8 | 10.0.0.0/8 | 10.0.0.0/8
291 11.1.2.3/8 | 10.0.0.0/8 | 10.0.0.0/8
292 9.1.2.3/8 | 10.0.0.0/8 | 8.0.0.0/8
293 10:23::f1/64 | 10:23::f1/128 | 10:23::f1
294 10:23::ffff | 10:23::8000/113 | 10:23::8000
295 ::4.3.2.1/24 | ::ffff:1.2.3.4/128 | ::0.2.2.0
298 SELECT i, c, i | c AS "or" FROM inet_tbl;
300 ------------------+--------------------+------------------
301 192.168.1.226/24 | 192.168.1.0/24 | 192.168.1.226/24
302 192.168.1.226 | 192.168.1.0/26 | 192.168.1.226
303 192.168.1.0/24 | 192.168.1.0/24 | 192.168.1.0/24
304 192.168.1.0/25 | 192.168.1.0/24 | 192.168.1.0/25
305 192.168.1.255/24 | 192.168.1.0/24 | 192.168.1.255/24
306 192.168.1.255/25 | 192.168.1.0/24 | 192.168.1.255/25
307 10.1.2.3/8 | 10.0.0.0/8 | 10.1.2.3/8
308 10.1.2.3/8 | 10.0.0.0/32 | 10.1.2.3
309 10.1.2.3 | 10.1.2.3/32 | 10.1.2.3
310 10.1.2.3/24 | 10.1.2.0/24 | 10.1.2.3/24
311 10.1.2.3/16 | 10.1.0.0/16 | 10.1.2.3/16
312 10.1.2.3/8 | 10.0.0.0/8 | 10.1.2.3/8
313 11.1.2.3/8 | 10.0.0.0/8 | 11.1.2.3/8
314 9.1.2.3/8 | 10.0.0.0/8 | 11.1.2.3/8
315 10:23::f1/64 | 10:23::f1/128 | 10:23::f1
316 10:23::ffff | 10:23::8000/113 | 10:23::ffff
317 ::4.3.2.1/24 | ::ffff:1.2.3.4/128 | ::ffff:5.3.3.5
320 SELECT i, i + 500 AS "i+500" FROM inet_tbl;
322 ------------------+------------------
323 192.168.1.226/24 | 192.168.3.214/24
324 192.168.1.226 | 192.168.3.214
325 192.168.1.0/24 | 192.168.2.244/24
326 192.168.1.0/25 | 192.168.2.244/25
327 192.168.1.255/24 | 192.168.3.243/24
328 192.168.1.255/25 | 192.168.3.243/25
329 10.1.2.3/8 | 10.1.3.247/8
330 10.1.2.3/8 | 10.1.3.247/8
331 10.1.2.3 | 10.1.3.247
332 10.1.2.3/24 | 10.1.3.247/24
333 10.1.2.3/16 | 10.1.3.247/16
334 10.1.2.3/8 | 10.1.3.247/8
335 11.1.2.3/8 | 11.1.3.247/8
336 9.1.2.3/8 | 9.1.3.247/8
337 10:23::f1/64 | 10:23::2e5/64
338 10:23::ffff | 10:23::1:1f3
339 ::4.3.2.1/24 | ::4.3.3.245/24
342 SELECT i, i - 500 AS "i-500" FROM inet_tbl;
344 ------------------+----------------------------------------
345 192.168.1.226/24 | 192.167.255.238/24
346 192.168.1.226 | 192.167.255.238
347 192.168.1.0/24 | 192.167.255.12/24
348 192.168.1.0/25 | 192.167.255.12/25
349 192.168.1.255/24 | 192.168.0.11/24
350 192.168.1.255/25 | 192.168.0.11/25
351 10.1.2.3/8 | 10.1.0.15/8
352 10.1.2.3/8 | 10.1.0.15/8
354 10.1.2.3/24 | 10.1.0.15/24
355 10.1.2.3/16 | 10.1.0.15/16
356 10.1.2.3/8 | 10.1.0.15/8
357 11.1.2.3/8 | 11.1.0.15/8
358 9.1.2.3/8 | 9.1.0.15/8
359 10:23::f1/64 | 10:22:ffff:ffff:ffff:ffff:ffff:fefd/64
360 10:23::ffff | 10:23::fe0b
361 ::4.3.2.1/24 | ::4.3.0.13/24
364 SELECT i, c, i - c AS "minus" FROM inet_tbl;
366 ------------------+--------------------+------------------
367 192.168.1.226/24 | 192.168.1.0/24 | 226
368 192.168.1.226 | 192.168.1.0/26 | 226
369 192.168.1.0/24 | 192.168.1.0/24 | 0
370 192.168.1.0/25 | 192.168.1.0/24 | 0
371 192.168.1.255/24 | 192.168.1.0/24 | 255
372 192.168.1.255/25 | 192.168.1.0/24 | 255
373 10.1.2.3/8 | 10.0.0.0/8 | 66051
374 10.1.2.3/8 | 10.0.0.0/32 | 66051
375 10.1.2.3 | 10.1.2.3/32 | 0
376 10.1.2.3/24 | 10.1.2.0/24 | 3
377 10.1.2.3/16 | 10.1.0.0/16 | 515
378 10.1.2.3/8 | 10.0.0.0/8 | 66051
379 11.1.2.3/8 | 10.0.0.0/8 | 16843267
380 9.1.2.3/8 | 10.0.0.0/8 | -16711165
381 10:23::f1/64 | 10:23::f1/128 | 0
382 10:23::ffff | 10:23::8000/113 | 32767
383 ::4.3.2.1/24 | ::ffff:1.2.3.4/128 | -281470631346435
386 SELECT '127.0.0.1'::inet + 257;
392 SELECT ('127.0.0.1'::inet + 257) - 257;
398 SELECT '127::1'::inet + 257;
404 SELECT ('127::1'::inet + 257) - 257;
410 SELECT '127.0.0.2'::inet - ('127.0.0.2'::inet + 500);
416 SELECT '127.0.0.2'::inet - ('127.0.0.2'::inet - 500);
422 SELECT '127::2'::inet - ('127::2'::inet + 500);
428 SELECT '127::2'::inet - ('127::2'::inet - 500);
434 -- these should give overflow errors:
435 SELECT '127.0.0.1'::inet + 10000000000;
436 ERROR: result is out of range
437 SELECT '127.0.0.1'::inet - 10000000000;
438 ERROR: result is out of range
439 SELECT '126::1'::inet - '127::2'::inet;
440 ERROR: result is out of range
441 SELECT '127::1'::inet - '126::2'::inet;
442 ERROR: result is out of range
444 SELECT '127::1'::inet + 10000000000;
450 SELECT '127::1'::inet - '127::2'::inet;