3 -- NOTE: int2 operators never check for over/underflow!
4 -- Some of these answers are consequently numerically incorrect.
6 CREATE TABLE INT2_TBL(f1 int2);
7 INSERT INTO INT2_TBL(f1) VALUES ('0 ');
8 INSERT INTO INT2_TBL(f1) VALUES (' 1234 ');
9 INSERT INTO INT2_TBL(f1) VALUES (' -1234');
10 INSERT INTO INT2_TBL(f1) VALUES ('34.5');
11 ERROR: invalid input syntax for integer: "34.5"
12 LINE 1: INSERT INTO INT2_TBL(f1) VALUES ('34.5');
14 -- largest and smallest values
15 INSERT INTO INT2_TBL(f1) VALUES ('32767');
16 INSERT INTO INT2_TBL(f1) VALUES ('-32767');
17 -- bad input values -- should give errors
18 INSERT INTO INT2_TBL(f1) VALUES ('100000');
19 ERROR: value "100000" is out of range for type smallint
20 LINE 1: INSERT INTO INT2_TBL(f1) VALUES ('100000');
22 INSERT INTO INT2_TBL(f1) VALUES ('asdf');
23 ERROR: invalid input syntax for integer: "asdf"
24 LINE 1: INSERT INTO INT2_TBL(f1) VALUES ('asdf');
26 INSERT INTO INT2_TBL(f1) VALUES (' ');
27 ERROR: invalid input syntax for integer: " "
28 LINE 1: INSERT INTO INT2_TBL(f1) VALUES (' ');
30 INSERT INTO INT2_TBL(f1) VALUES ('- 1234');
31 ERROR: invalid input syntax for integer: "- 1234"
32 LINE 1: INSERT INTO INT2_TBL(f1) VALUES ('- 1234');
34 INSERT INTO INT2_TBL(f1) VALUES ('4 444');
35 ERROR: invalid input syntax for integer: "4 444"
36 LINE 1: INSERT INTO INT2_TBL(f1) VALUES ('4 444');
38 INSERT INTO INT2_TBL(f1) VALUES ('123 dt');
39 ERROR: invalid input syntax for integer: "123 dt"
40 LINE 1: INSERT INTO INT2_TBL(f1) VALUES ('123 dt');
42 INSERT INTO INT2_TBL(f1) VALUES ('');
43 ERROR: invalid input syntax for integer: ""
44 LINE 1: INSERT INTO INT2_TBL(f1) VALUES ('');
46 SELECT '' AS five, * FROM INT2_TBL;
56 SELECT '' AS four, i.* FROM INT2_TBL i WHERE i.f1 <> int2 '0';
65 SELECT '' AS four, i.* FROM INT2_TBL i WHERE i.f1 <> int4 '0';
74 SELECT '' AS one, i.* FROM INT2_TBL i WHERE i.f1 = int2 '0';
80 SELECT '' AS one, i.* FROM INT2_TBL i WHERE i.f1 = int4 '0';
86 SELECT '' AS two, i.* FROM INT2_TBL i WHERE i.f1 < int2 '0';
93 SELECT '' AS two, i.* FROM INT2_TBL i WHERE i.f1 < int4 '0';
100 SELECT '' AS three, i.* FROM INT2_TBL i WHERE i.f1 <= int2 '0';
108 SELECT '' AS three, i.* FROM INT2_TBL i WHERE i.f1 <= int4 '0';
116 SELECT '' AS two, i.* FROM INT2_TBL i WHERE i.f1 > int2 '0';
123 SELECT '' AS two, i.* FROM INT2_TBL i WHERE i.f1 > int4 '0';
130 SELECT '' AS three, i.* FROM INT2_TBL i WHERE i.f1 >= int2 '0';
138 SELECT '' AS three, i.* FROM INT2_TBL i WHERE i.f1 >= int4 '0';
147 SELECT '' AS one, i.* FROM INT2_TBL i WHERE (i.f1 % int2 '2') = int2 '1';
154 SELECT '' AS three, i.* FROM INT2_TBL i WHERE (i.f1 % int4 '2') = int2 '0';
162 SELECT '' AS five, i.f1, i.f1 * int2 '2' AS x FROM INT2_TBL i;
163 ERROR: smallint out of range
164 SELECT '' AS five, i.f1, i.f1 * int2 '2' AS x FROM INT2_TBL i
165 WHERE abs(f1) < 16384;
167 ------+-------+-------
173 SELECT '' AS five, i.f1, i.f1 * int4 '2' AS x FROM INT2_TBL i;
175 ------+--------+--------
183 SELECT '' AS five, i.f1, i.f1 + int2 '2' AS x FROM INT2_TBL i;
184 ERROR: smallint out of range
185 SELECT '' AS five, i.f1, i.f1 + int2 '2' AS x FROM INT2_TBL i
188 ------+--------+--------
195 SELECT '' AS five, i.f1, i.f1 + int4 '2' AS x FROM INT2_TBL i;
197 ------+--------+--------
205 SELECT '' AS five, i.f1, i.f1 - int2 '2' AS x FROM INT2_TBL i;
206 ERROR: smallint out of range
207 SELECT '' AS five, i.f1, i.f1 - int2 '2' AS x FROM INT2_TBL i
210 ------+-------+-------
217 SELECT '' AS five, i.f1, i.f1 - int4 '2' AS x FROM INT2_TBL i;
219 ------+--------+--------
227 SELECT '' AS five, i.f1, i.f1 / int2 '2' AS x FROM INT2_TBL i;
229 ------+--------+--------
237 SELECT '' AS five, i.f1, i.f1 / int4 '2' AS x FROM INT2_TBL i;
239 ------+--------+--------