17 -- boxes are specified by two points, given by four floats x1,y1,x2,y2
18 CREATE TABLE BOX_TBL (f1 box);
19 INSERT INTO BOX_TBL (f1) VALUES ('(2.0,2.0,0.0,0.0)');
20 INSERT INTO BOX_TBL (f1) VALUES ('(1.0,1.0,3.0,3.0)');
21 -- degenerate cases where the box is a line or a point
22 -- note that lines and points boxes all have zero area
23 INSERT INTO BOX_TBL (f1) VALUES ('(2.5, 2.5, 2.5,3.5)');
24 INSERT INTO BOX_TBL (f1) VALUES ('(3.0, 3.0,3.0,3.0)');
25 -- badly formatted box inputs
26 INSERT INTO BOX_TBL (f1) VALUES ('(2.3, 4.5)');
27 ERROR: invalid input syntax for type box: "(2.3, 4.5)"
28 LINE 1: INSERT INTO BOX_TBL (f1) VALUES ('(2.3, 4.5)');
30 INSERT INTO BOX_TBL (f1) VALUES ('asdfasdf(ad');
31 ERROR: invalid input syntax for type box: "asdfasdf(ad"
32 LINE 1: INSERT INTO BOX_TBL (f1) VALUES ('asdfasdf(ad');
34 SELECT '' AS four, * FROM BOX_TBL;
36 ------+---------------------
43 SELECT '' AS four, b.*, area(b.f1) as barea
46 ------+---------------------+-------
49 | (2.5,3.5),(2.5,2.5) | 0
54 SELECT '' AS three, b.f1
56 WHERE b.f1 && box '(2.5,2.5,1.0,1.0)';
58 -------+---------------------
64 -- left-or-overlap (x only)
65 SELECT '' AS two, b1.*
67 WHERE b1.f1 &< box '(2.0,2.0,2.5,2.5)';
69 -----+---------------------
74 -- right-or-overlap (x only)
75 SELECT '' AS two, b1.*
77 WHERE b1.f1 &> box '(2.0,2.0,2.5,2.5)';
79 -----+---------------------
85 SELECT '' AS two, b.f1
87 WHERE b.f1 << box '(3.0,3.0,5.0,5.0)';
89 -----+---------------------
95 SELECT '' AS four, b.f1
97 WHERE b.f1 <= box '(3.0,3.0,5.0,5.0)';
99 ------+---------------------
102 | (2.5,3.5),(2.5,2.5)
107 SELECT '' AS two, b.f1
109 WHERE b.f1 < box '(3.0,3.0,5.0,5.0)';
111 -----+---------------------
112 | (2.5,3.5),(2.5,2.5)
117 SELECT '' AS two, b.f1
119 WHERE b.f1 = box '(3.0,3.0,5.0,5.0)';
127 SELECT '' AS two, b.f1
128 FROM BOX_TBL b -- zero area
129 WHERE b.f1 > box '(3.5,3.0,4.5,3.0)';
137 SELECT '' AS four, b.f1
138 FROM BOX_TBL b -- zero area
139 WHERE b.f1 >= box '(3.5,3.0,4.5,3.0)';
141 ------+---------------------
144 | (2.5,3.5),(2.5,2.5)
149 SELECT '' AS two, b.f1
151 WHERE box '(3.0,3.0,5.0,5.0)' >> b.f1;
153 -----+---------------------
155 | (2.5,3.5),(2.5,2.5)
159 SELECT '' AS three, b.f1
161 WHERE b.f1 <@ box '(0,0,3,3)';
163 -------+-------------
170 SELECT '' AS three, b.f1
172 WHERE box '(0,0,3,3)' @> b.f1;
174 -------+-------------
181 SELECT '' AS one, b.f1
183 WHERE box '(1,1,3,3)' ~= b.f1;
189 -- center of box, left unary operator
190 SELECT '' AS four, @@(b1.f1) AS p
201 SELECT '' AS one, b1.*, b2.*
202 FROM BOX_TBL b1, BOX_TBL b2
203 WHERE b1.f1 @> b2.f1 and not b1.f1 ~= b2.f1;
205 -----+-------------+-------------
206 | (3,3),(1,1) | (3,3),(3,3)
209 SELECT '' AS four, height(f1), width(f1) FROM BOX_TBL;
210 four | height | width
211 ------+--------+-------