16 CREATE TABLE POLYGON_TBL(f1 polygon);
17 INSERT INTO POLYGON_TBL(f1) VALUES ('(2.0,0.0),(2.0,4.0),(0.0,0.0)');
18 INSERT INTO POLYGON_TBL(f1) VALUES ('(3.0,1.0),(3.0,3.0),(1.0,0.0)');
19 -- degenerate polygons
20 INSERT INTO POLYGON_TBL(f1) VALUES ('(0.0,0.0)');
21 INSERT INTO POLYGON_TBL(f1) VALUES ('(0.0,1.0),(0.0,1.0)');
22 -- bad polygon input strings
23 INSERT INTO POLYGON_TBL(f1) VALUES ('0.0');
24 ERROR: invalid input syntax for type polygon: "0.0"
25 LINE 1: INSERT INTO POLYGON_TBL(f1) VALUES ('0.0');
27 INSERT INTO POLYGON_TBL(f1) VALUES ('(0.0 0.0');
28 ERROR: invalid input syntax for type polygon: "(0.0 0.0"
29 LINE 1: INSERT INTO POLYGON_TBL(f1) VALUES ('(0.0 0.0');
31 INSERT INTO POLYGON_TBL(f1) VALUES ('(0,1,2)');
32 ERROR: invalid input syntax for type polygon: "(0,1,2)"
33 LINE 1: INSERT INTO POLYGON_TBL(f1) VALUES ('(0,1,2)');
35 INSERT INTO POLYGON_TBL(f1) VALUES ('(0,1,2,3');
36 ERROR: invalid input syntax for type polygon: "(0,1,2,3"
37 LINE 1: INSERT INTO POLYGON_TBL(f1) VALUES ('(0,1,2,3');
39 INSERT INTO POLYGON_TBL(f1) VALUES ('asdf');
40 ERROR: invalid input syntax for type polygon: "asdf"
41 LINE 1: INSERT INTO POLYGON_TBL(f1) VALUES ('asdf');
43 SELECT '' AS four, * FROM POLYGON_TBL;
45 ------+---------------------
53 SELECT '' AS three, p.*
55 WHERE p.f1 && '(3.0,1.0),(3.0,3.0),(1.0,0.0)';
57 -------+---------------------
63 SELECT '' AS four, p.*
65 WHERE p.f1 &< '(3.0,1.0),(3.0,3.0),(1.0,0.0)';
67 ------+---------------------
77 WHERE p.f1 &> '(3.0,1.0),(3.0,3.0),(1.0,0.0)';
79 -----+---------------------
86 WHERE p.f1 << '(3.0,1.0),(3.0,3.0),(1.0,0.0)';
94 SELECT '' AS zero, p.*
96 WHERE p.f1 >> '(3.0,1.0),(3.0,3.0),(1.0,0.0)';
102 SELECT '' AS one, p.*
104 WHERE p.f1 <@ polygon '(3.0,1.0),(3.0,3.0),(1.0,0.0)';
106 -----+---------------------
107 | ((3,1),(3,3),(1,0))
111 SELECT '' AS one, p.*
113 WHERE p.f1 ~= polygon '(3.0,1.0),(3.0,3.0),(1.0,0.0)';
115 -----+---------------------
116 | ((3,1),(3,3),(1,0))
120 SELECT '' AS one, p.*
122 WHERE p.f1 @> polygon '(3.0,1.0),(3.0,3.0),(1.0,0.0)';
124 -----+---------------------
125 | ((3,1),(3,3),(1,0))
142 SELECT polygon '(2.0,0.0),(2.0,4.0),(0.0,0.0)' << polygon '(3.0,1.0),(3.0,3.0),(1.0,0.0)' AS false;
149 SELECT polygon '(2.0,0.0),(2.0,4.0),(0.0,0.0)' << polygon '(3.0,1.0),(3.0,3.0),(1.0,0.0)' AS true;
156 SELECT polygon '(2.0,0.0),(2.0,4.0),(0.0,0.0)' &> polygon '(3.0,1.0),(3.0,3.0),(1.0,0.0)' AS false;
163 SELECT polygon '(2.0,0.0),(2.0,4.0),(0.0,0.0)' >> polygon '(3.0,1.0),(3.0,3.0),(1.0,0.0)' AS false;
170 SELECT polygon '(2.0,0.0),(2.0,4.0),(0.0,0.0)' <@ polygon '(3.0,1.0),(3.0,3.0),(1.0,0.0)' AS false;
177 SELECT polygon '(2.0,0.0),(2.0,4.0),(0.0,0.0)' @> polygon '(3.0,1.0),(3.0,3.0),(1.0,0.0)' AS false;
183 -- +------------------------+
187 -- +------------------------+
189 -- endpoints '+' is ofr one polygon, '*' - for another
190 -- Edges 1-2, 2-3 are not shown on picture
191 SELECT '((0,4),(6,4),(1,2),(6,0),(0,0))'::polygon @> '((2,1),(2,3),(3,3),(3,1))'::polygon AS "false";
204 SELECT '((0,4),(6,4),(3,2),(6,0),(0,0))'::polygon @> '((2,1),(2,3),(3,3),(3,1))'::polygon AS "true";
210 -- +-----------------+
216 -- +-----------------+
217 SELECT '((1,1),(1,4),(5,4),(5,3),(2,3),(2,2),(5,2),(5,1))'::polygon @> '((3,2),(3,3),(4,3),(4,2))'::polygon AS "false";
230 SELECT '((0,0),(0,3),(3,3),(3,0))'::polygon @> '((2,1),(2,2),(3,2),(3,1))'::polygon AS "true";
237 SELECT polygon '(2.0,0.0),(2.0,4.0),(0.0,0.0)' ~= polygon '(3.0,1.0),(3.0,3.0),(1.0,0.0)' AS false;
244 SELECT polygon '(2.0,0.0),(2.0,4.0),(0.0,0.0)' && polygon '(3.0,1.0),(3.0,3.0),(1.0,0.0)' AS true;
250 -- +--------------------+
254 -- +--------------------+
256 -- Edges 1-2, 2-3 are not shown on picture
257 SELECT '((0,4),(6,4),(1,2),(6,0),(0,0))'::polygon && '((2,1),(2,3),(3,3),(3,1))'::polygon AS "true";
269 SELECT '((1,4),(1,1),(4,1),(4,2),(2,2),(2,4),(1,4))'::polygon && '((3,3),(4,3),(4,4),(3,4),(3,3))'::polygon AS "false";
275 SELECT '((200,800),(800,800),(800,200),(200,200))' && '(1000,1000,0,0)'::polygon AS "true";