4 CREATE TABLE INT2_TBL(f1 int2);
5 INSERT INTO INT2_TBL(f1) VALUES ('0 ');
6 INSERT INTO INT2_TBL(f1) VALUES (' 1234 ');
7 INSERT INTO INT2_TBL(f1) VALUES (' -1234');
8 INSERT INTO INT2_TBL(f1) VALUES ('34.5');
9 ERROR: invalid input syntax for integer: "34.5"
10 LINE 1: INSERT INTO INT2_TBL(f1) VALUES ('34.5');
12 -- largest and smallest values
13 INSERT INTO INT2_TBL(f1) VALUES ('32767');
14 INSERT INTO INT2_TBL(f1) VALUES ('-32767');
15 -- bad input values -- should give errors
16 INSERT INTO INT2_TBL(f1) VALUES ('100000');
17 ERROR: value "100000" is out of range for type smallint
18 LINE 1: INSERT INTO INT2_TBL(f1) VALUES ('100000');
20 INSERT INTO INT2_TBL(f1) VALUES ('asdf');
21 ERROR: invalid input syntax for integer: "asdf"
22 LINE 1: INSERT INTO INT2_TBL(f1) VALUES ('asdf');
24 INSERT INTO INT2_TBL(f1) VALUES (' ');
25 ERROR: invalid input syntax for integer: " "
26 LINE 1: INSERT INTO INT2_TBL(f1) VALUES (' ');
28 INSERT INTO INT2_TBL(f1) VALUES ('- 1234');
29 ERROR: invalid input syntax for integer: "- 1234"
30 LINE 1: INSERT INTO INT2_TBL(f1) VALUES ('- 1234');
32 INSERT INTO INT2_TBL(f1) VALUES ('4 444');
33 ERROR: invalid input syntax for integer: "4 444"
34 LINE 1: INSERT INTO INT2_TBL(f1) VALUES ('4 444');
36 INSERT INTO INT2_TBL(f1) VALUES ('123 dt');
37 ERROR: invalid input syntax for integer: "123 dt"
38 LINE 1: INSERT INTO INT2_TBL(f1) VALUES ('123 dt');
40 INSERT INTO INT2_TBL(f1) VALUES ('');
41 ERROR: invalid input syntax for integer: ""
42 LINE 1: INSERT INTO INT2_TBL(f1) VALUES ('');
44 SELECT '' AS five, * FROM INT2_TBL;
54 SELECT '' AS four, i.* FROM INT2_TBL i WHERE i.f1 <> int2 '0';
63 SELECT '' AS four, i.* FROM INT2_TBL i WHERE i.f1 <> int4 '0';
72 SELECT '' AS one, i.* FROM INT2_TBL i WHERE i.f1 = int2 '0';
78 SELECT '' AS one, i.* FROM INT2_TBL i WHERE i.f1 = int4 '0';
84 SELECT '' AS two, i.* FROM INT2_TBL i WHERE i.f1 < int2 '0';
91 SELECT '' AS two, i.* FROM INT2_TBL i WHERE i.f1 < int4 '0';
98 SELECT '' AS three, i.* FROM INT2_TBL i WHERE i.f1 <= int2 '0';
106 SELECT '' AS three, i.* FROM INT2_TBL i WHERE i.f1 <= int4 '0';
114 SELECT '' AS two, i.* FROM INT2_TBL i WHERE i.f1 > int2 '0';
121 SELECT '' AS two, i.* FROM INT2_TBL i WHERE i.f1 > int4 '0';
128 SELECT '' AS three, i.* FROM INT2_TBL i WHERE i.f1 >= int2 '0';
136 SELECT '' AS three, i.* FROM INT2_TBL i WHERE i.f1 >= int4 '0';
145 SELECT '' AS one, i.* FROM INT2_TBL i WHERE (i.f1 % int2 '2') = int2 '1';
152 SELECT '' AS three, i.* FROM INT2_TBL i WHERE (i.f1 % int4 '2') = int2 '0';
160 SELECT '' AS five, i.f1, i.f1 * int2 '2' AS x FROM INT2_TBL i;
161 ERROR: smallint out of range
162 SELECT '' AS five, i.f1, i.f1 * int2 '2' AS x FROM INT2_TBL i
163 WHERE abs(f1) < 16384;
165 ------+-------+-------
171 SELECT '' AS five, i.f1, i.f1 * int4 '2' AS x FROM INT2_TBL i;
173 ------+--------+--------
181 SELECT '' AS five, i.f1, i.f1 + int2 '2' AS x FROM INT2_TBL i;
182 ERROR: smallint out of range
183 SELECT '' AS five, i.f1, i.f1 + int2 '2' AS x FROM INT2_TBL i
186 ------+--------+--------
193 SELECT '' AS five, i.f1, i.f1 + int4 '2' AS x FROM INT2_TBL i;
195 ------+--------+--------
203 SELECT '' AS five, i.f1, i.f1 - int2 '2' AS x FROM INT2_TBL i;
204 ERROR: smallint out of range
205 SELECT '' AS five, i.f1, i.f1 - int2 '2' AS x FROM INT2_TBL i
208 ------+-------+-------
215 SELECT '' AS five, i.f1, i.f1 - int4 '2' AS x FROM INT2_TBL i;
217 ------+--------+--------
225 SELECT '' AS five, i.f1, i.f1 / int2 '2' AS x FROM INT2_TBL i;
227 ------+--------+--------
235 SELECT '' AS five, i.f1, i.f1 / int4 '2' AS x FROM INT2_TBL i;
237 ------+--------+--------
246 SELECT (-1::int2<<15)::text;
252 SELECT ((-1::int2<<15)+1::int2)::text;