5 -- first, define the datatype. Turn off echoing so that expected file
6 -- does not depend on contents of seg.sql.
8 SET client_min_messages = warning;
10 RESET client_min_messages;
12 -- testing the input and output functions
15 SELECT '1'::seg AS seg;
21 SELECT '-1'::seg AS seg;
27 SELECT '1.0'::seg AS seg;
33 SELECT '-1.0'::seg AS seg;
39 SELECT '1e7'::seg AS seg;
45 SELECT '-1e7'::seg AS seg;
51 SELECT '1.0e7'::seg AS seg;
57 SELECT '-1.0e7'::seg AS seg;
63 SELECT '1e+7'::seg AS seg;
69 SELECT '-1e+7'::seg AS seg;
75 SELECT '1.0e+7'::seg AS seg;
81 SELECT '-1.0e+7'::seg AS seg;
87 SELECT '1e-7'::seg AS seg;
93 SELECT '-1e-7'::seg AS seg;
99 SELECT '1.0e-7'::seg AS seg;
105 SELECT '-1.0e-7'::seg AS seg;
111 SELECT '2e-6'::seg AS seg;
117 SELECT '2e-5'::seg AS seg;
123 SELECT '2e-4'::seg AS seg;
129 SELECT '2e-3'::seg AS seg;
135 SELECT '2e-2'::seg AS seg;
141 SELECT '2e-1'::seg AS seg;
147 SELECT '2e-0'::seg AS seg;
153 SELECT '2e+0'::seg AS seg;
159 SELECT '2e+1'::seg AS seg;
165 SELECT '2e+2'::seg AS seg;
171 SELECT '2e+3'::seg AS seg;
177 SELECT '2e+4'::seg AS seg;
183 SELECT '2e+5'::seg AS seg;
189 SELECT '2e+6'::seg AS seg;
195 -- Significant digits preserved
196 SELECT '1'::seg AS seg;
202 SELECT '1.0'::seg AS seg;
208 SELECT '1.00'::seg AS seg;
214 SELECT '1.000'::seg AS seg;
220 SELECT '1.0000'::seg AS seg;
226 SELECT '1.00000'::seg AS seg;
232 SELECT '1.000000'::seg AS seg;
238 SELECT '0.000000120'::seg AS seg;
244 SELECT '3.400e5'::seg AS seg;
251 SELECT '12.34567890123456'::seg AS seg;
257 -- Numbers with certainty indicators
258 SELECT '~6.5'::seg AS seg;
264 SELECT '<6.5'::seg AS seg;
270 SELECT '>6.5'::seg AS seg;
276 SELECT '~ 6.5'::seg AS seg;
282 SELECT '< 6.5'::seg AS seg;
288 SELECT '> 6.5'::seg AS seg;
295 SELECT '0..'::seg AS seg;
301 SELECT '0...'::seg AS seg;
307 SELECT '0 ..'::seg AS seg;
313 SELECT '0 ...'::seg AS seg;
319 SELECT '..0'::seg AS seg;
325 SELECT '...0'::seg AS seg;
331 SELECT '.. 0'::seg AS seg;
337 SELECT '... 0'::seg AS seg;
344 SELECT '0 .. 1'::seg AS seg;
350 SELECT '-1 .. 0'::seg AS seg;
356 SELECT '-1 .. 1'::seg AS seg;
363 SELECT '0(+-)1'::seg AS seg;
369 SELECT '0(+-)1.0'::seg AS seg;
375 SELECT '1.0(+-)0.005'::seg AS seg;
381 SELECT '101(+-)1'::seg AS seg;
387 -- incorrect number of significant digits in 99.0:
388 SELECT '100(+-)1'::seg AS seg;
395 SELECT ''::seg AS seg;
396 ERROR: bad seg representation
397 LINE 1: SELECT ''::seg AS seg;
399 DETAIL: syntax error at end of input
400 SELECT 'ABC'::seg AS seg;
401 ERROR: bad seg representation
402 LINE 1: SELECT 'ABC'::seg AS seg;
404 DETAIL: syntax error at or near "A"
405 SELECT '1ABC'::seg AS seg;
406 ERROR: bad seg representation
407 LINE 1: SELECT '1ABC'::seg AS seg;
409 DETAIL: syntax error at or near "A"
410 SELECT '1.'::seg AS seg;
411 ERROR: bad seg representation
412 LINE 1: SELECT '1.'::seg AS seg;
414 DETAIL: syntax error at or near "."
415 SELECT '1.....'::seg AS seg;
416 ERROR: bad seg representation
417 LINE 1: SELECT '1.....'::seg AS seg;
419 DETAIL: syntax error at or near ".."
420 SELECT '.1'::seg AS seg;
421 ERROR: bad seg representation
422 LINE 1: SELECT '.1'::seg AS seg;
424 DETAIL: syntax error at or near "."
425 SELECT '1..2.'::seg AS seg;
426 ERROR: bad seg representation
427 LINE 1: SELECT '1..2.'::seg AS seg;
429 DETAIL: syntax error at or near "."
430 SELECT '1 e7'::seg AS seg;
431 ERROR: bad seg representation
432 LINE 1: SELECT '1 e7'::seg AS seg;
434 DETAIL: syntax error at or near "e"
435 SELECT '1e700'::seg AS seg;
436 ERROR: "1e700" is out of range for type real
437 LINE 1: SELECT '1e700'::seg AS seg;
440 -- testing the operators
442 -- equality/inequality:
444 SELECT '24 .. 33.20'::seg = '24 .. 33.20'::seg AS bool;
450 SELECT '24 .. 33.20'::seg = '24 .. 33.21'::seg AS bool;
456 SELECT '24 .. 33.20'::seg != '24 .. 33.20'::seg AS bool;
462 SELECT '24 .. 33.20'::seg != '24 .. 33.21'::seg AS bool;
470 SELECT '1'::seg && '1'::seg AS bool;
476 SELECT '1'::seg && '2'::seg AS bool;
482 SELECT '0 ..'::seg && '0 ..'::seg AS bool;
488 SELECT '0 .. 1'::seg && '0 .. 1'::seg AS bool;
494 SELECT '..0'::seg && '0..'::seg AS bool;
500 SELECT '-1 .. 0.1'::seg && '0 .. 1'::seg AS bool;
506 SELECT '-1 .. 0'::seg && '0 .. 1'::seg AS bool;
512 SELECT '-1 .. -0.0001'::seg && '0 .. 1'::seg AS bool;
518 SELECT '0 ..'::seg && '1'::seg AS bool;
524 SELECT '0 .. 1'::seg && '1'::seg AS bool;
530 SELECT '0 .. 1'::seg && '2'::seg AS bool;
536 SELECT '0 .. 2'::seg && '1'::seg AS bool;
542 SELECT '1'::seg && '0 .. 1'::seg AS bool;
548 SELECT '2'::seg && '0 .. 1'::seg AS bool;
554 SELECT '1'::seg && '0 .. 2'::seg AS bool;
560 -- overlap on the left
562 SELECT '1'::seg &< '0'::seg AS bool;
568 SELECT '1'::seg &< '1'::seg AS bool;
574 SELECT '1'::seg &< '2'::seg AS bool;
580 SELECT '0 .. 1'::seg &< '0'::seg AS bool;
586 SELECT '0 .. 1'::seg &< '1'::seg AS bool;
592 SELECT '0 .. 1'::seg &< '2'::seg AS bool;
598 SELECT '0 .. 1'::seg &< '0 .. 0.5'::seg AS bool;
604 SELECT '0 .. 1'::seg &< '0 .. 1'::seg AS bool;
610 SELECT '0 .. 1'::seg &< '0 .. 2'::seg AS bool;
616 SELECT '0 .. 1'::seg &< '1 .. 2'::seg AS bool;
622 SELECT '0 .. 1'::seg &< '2 .. 3'::seg AS bool;
628 -- overlap on the right
630 SELECT '0'::seg &> '1'::seg AS bool;
636 SELECT '1'::seg &> '1'::seg AS bool;
642 SELECT '2'::seg &> '1'::seg AS bool;
648 SELECT '0'::seg &> '0 .. 1'::seg AS bool;
654 SELECT '1'::seg &> '0 .. 1'::seg AS bool;
660 SELECT '2'::seg &> '0 .. 1'::seg AS bool;
666 SELECT '0 .. 0.5'::seg &> '0 .. 1'::seg AS bool;
672 SELECT '0 .. 1'::seg &> '0 .. 1'::seg AS bool;
678 SELECT '0 .. 2'::seg &> '0 .. 2'::seg AS bool;
684 SELECT '1 .. 2'::seg &> '0 .. 1'::seg AS bool;
690 SELECT '2 .. 3'::seg &> '0 .. 1'::seg AS bool;
698 SELECT '1'::seg << '0'::seg AS bool;
704 SELECT '1'::seg << '1'::seg AS bool;
710 SELECT '1'::seg << '2'::seg AS bool;
716 SELECT '0 .. 1'::seg << '0'::seg AS bool;
722 SELECT '0 .. 1'::seg << '1'::seg AS bool;
728 SELECT '0 .. 1'::seg << '2'::seg AS bool;
734 SELECT '0 .. 1'::seg << '0 .. 0.5'::seg AS bool;
740 SELECT '0 .. 1'::seg << '0 .. 1'::seg AS bool;
746 SELECT '0 .. 1'::seg << '0 .. 2'::seg AS bool;
752 SELECT '0 .. 1'::seg << '1 .. 2'::seg AS bool;
758 SELECT '0 .. 1'::seg << '2 .. 3'::seg AS bool;
766 SELECT '0'::seg >> '1'::seg AS bool;
772 SELECT '1'::seg >> '1'::seg AS bool;
778 SELECT '2'::seg >> '1'::seg AS bool;
784 SELECT '0'::seg >> '0 .. 1'::seg AS bool;
790 SELECT '1'::seg >> '0 .. 1'::seg AS bool;
796 SELECT '2'::seg >> '0 .. 1'::seg AS bool;
802 SELECT '0 .. 0.5'::seg >> '0 .. 1'::seg AS bool;
808 SELECT '0 .. 1'::seg >> '0 .. 1'::seg AS bool;
814 SELECT '0 .. 2'::seg >> '0 .. 2'::seg AS bool;
820 SELECT '1 .. 2'::seg >> '0 .. 1'::seg AS bool;
826 SELECT '2 .. 3'::seg >> '0 .. 1'::seg AS bool;
832 -- "contained in" (the left value belongs within the interval specified in the right value):
834 SELECT '0'::seg <@ '0'::seg AS bool;
840 SELECT '0'::seg <@ '0 ..'::seg AS bool;
846 SELECT '0'::seg <@ '.. 0'::seg AS bool;
852 SELECT '0'::seg <@ '-1 .. 1'::seg AS bool;
858 SELECT '0'::seg <@ '-1 .. 1'::seg AS bool;
864 SELECT '-1'::seg <@ '-1 .. 1'::seg AS bool;
870 SELECT '1'::seg <@ '-1 .. 1'::seg AS bool;
876 SELECT '-1 .. 1'::seg <@ '-1 .. 1'::seg AS bool;
882 -- "contains" (the left value contains the interval specified in the right value):
884 SELECT '0'::seg @> '0'::seg AS bool;
890 SELECT '0 .. '::seg <@ '0'::seg AS bool;
896 SELECT '.. 0'::seg <@ '0'::seg AS bool;
902 SELECT '-1 .. 1'::seg <@ '0'::seg AS bool;
908 SELECT '0'::seg <@ '-1 .. 1'::seg AS bool;
914 SELECT '-1'::seg <@ '-1 .. 1'::seg AS bool;
920 SELECT '1'::seg <@ '-1 .. 1'::seg AS bool;
926 -- Load some example data and build the index
928 CREATE TABLE test_seg (s seg);
929 \copy test_seg from 'data/test_seg.data'
930 CREATE INDEX test_seg_ix ON test_seg USING gist (s);
931 SELECT count(*) FROM test_seg WHERE s @> '11..11.3';
938 SELECT * FROM test_seg WHERE s @> '11..11.3' GROUP BY s;
1087 SELECT seg_lower(s), seg_center(s), seg_upper(s)
1088 FROM test_seg WHERE s @> '11.2..11.3' OR s IS NULL ORDER BY s;
1089 seg_lower | seg_center | seg_upper
1090 -----------+------------+-----------
1091 -Infinity | -Infinity | 40
1092 -Infinity | -Infinity | 82
1093 -Infinity | -Infinity | 90
1098 2.3 | Infinity | Infinity
1099 2.3 | Infinity | Infinity
1103 2.6 | Infinity | Infinity
1105 3 | Infinity | Infinity
1111 4 | Infinity | Infinity
1117 4 | Infinity | Infinity
1130 4.8 | Infinity | Infinity
1132 4.9 | Infinity | Infinity
1149 5.3 | Infinity | Infinity
1150 5.4 | Infinity | Infinity
1157 5.5 | Infinity | Infinity
1158 5.5 | Infinity | Infinity
1159 5.7 | Infinity | Infinity
1160 5.9 | Infinity | Infinity
1167 6.1 | Infinity | Infinity
1169 6.3 | Infinity | Infinity
1173 6.5 | Infinity | Infinity
1174 6.6 | Infinity | Infinity
1176 6.7 | Infinity | Infinity
1177 6.75 | Infinity | Infinity
1178 6.8 | Infinity | Infinity
1181 6.9 | Infinity | Infinity
1185 7 | Infinity | Infinity
1186 7.15 | Infinity | Infinity
1189 7.3 | Infinity | Infinity
1190 7.3 | Infinity | Infinity
1192 7.4 | Infinity | Infinity
1195 7.5 | Infinity | Infinity
1197 7.7 | Infinity | Infinity
1198 7.75 | Infinity | Infinity
1202 8.2 | Infinity | Infinity
1203 8.3 | Infinity | Infinity
1206 8.5 | Infinity | Infinity
1215 9 | Infinity | Infinity
1220 9.5 | Infinity | Infinity