4 CREATE TABLE INT4_TBL(f1 int4);
5 INSERT INTO INT4_TBL(f1) VALUES (' 0 ');
6 INSERT INTO INT4_TBL(f1) VALUES ('123456 ');
7 INSERT INTO INT4_TBL(f1) VALUES (' -123456');
8 INSERT INTO INT4_TBL(f1) VALUES ('34.5');
9 ERROR: invalid input syntax for integer: "34.5"
10 LINE 1: INSERT INTO INT4_TBL(f1) VALUES ('34.5');
12 -- largest and smallest values
13 INSERT INTO INT4_TBL(f1) VALUES ('2147483647');
14 INSERT INTO INT4_TBL(f1) VALUES ('-2147483647');
15 -- bad input values -- should give errors
16 INSERT INTO INT4_TBL(f1) VALUES ('1000000000000');
17 ERROR: value "1000000000000" is out of range for type integer
18 LINE 1: INSERT INTO INT4_TBL(f1) VALUES ('1000000000000');
20 INSERT INTO INT4_TBL(f1) VALUES ('asdf');
21 ERROR: invalid input syntax for integer: "asdf"
22 LINE 1: INSERT INTO INT4_TBL(f1) VALUES ('asdf');
24 INSERT INTO INT4_TBL(f1) VALUES (' ');
25 ERROR: invalid input syntax for integer: " "
26 LINE 1: INSERT INTO INT4_TBL(f1) VALUES (' ');
28 INSERT INTO INT4_TBL(f1) VALUES (' asdf ');
29 ERROR: invalid input syntax for integer: " asdf "
30 LINE 1: INSERT INTO INT4_TBL(f1) VALUES (' asdf ');
32 INSERT INTO INT4_TBL(f1) VALUES ('- 1234');
33 ERROR: invalid input syntax for integer: "- 1234"
34 LINE 1: INSERT INTO INT4_TBL(f1) VALUES ('- 1234');
36 INSERT INTO INT4_TBL(f1) VALUES ('123 5');
37 ERROR: invalid input syntax for integer: "123 5"
38 LINE 1: INSERT INTO INT4_TBL(f1) VALUES ('123 5');
40 INSERT INTO INT4_TBL(f1) VALUES ('');
41 ERROR: invalid input syntax for integer: ""
42 LINE 1: INSERT INTO INT4_TBL(f1) VALUES ('');
44 SELECT '' AS five, * FROM INT4_TBL;
54 SELECT '' AS four, i.* FROM INT4_TBL i WHERE i.f1 <> int2 '0';
63 SELECT '' AS four, i.* FROM INT4_TBL i WHERE i.f1 <> int4 '0';
72 SELECT '' AS one, i.* FROM INT4_TBL i WHERE i.f1 = int2 '0';
78 SELECT '' AS one, i.* FROM INT4_TBL i WHERE i.f1 = int4 '0';
84 SELECT '' AS two, i.* FROM INT4_TBL i WHERE i.f1 < int2 '0';
91 SELECT '' AS two, i.* FROM INT4_TBL i WHERE i.f1 < int4 '0';
98 SELECT '' AS three, i.* FROM INT4_TBL i WHERE i.f1 <= int2 '0';
100 -------+-------------
106 SELECT '' AS three, i.* FROM INT4_TBL i WHERE i.f1 <= int4 '0';
108 -------+-------------
114 SELECT '' AS two, i.* FROM INT4_TBL i WHERE i.f1 > int2 '0';
121 SELECT '' AS two, i.* FROM INT4_TBL i WHERE i.f1 > int4 '0';
128 SELECT '' AS three, i.* FROM INT4_TBL i WHERE i.f1 >= int2 '0';
136 SELECT '' AS three, i.* FROM INT4_TBL i WHERE i.f1 >= int4 '0';
145 SELECT '' AS one, i.* FROM INT4_TBL i WHERE (i.f1 % int2 '2') = int2 '1';
152 SELECT '' AS three, i.* FROM INT4_TBL i WHERE (i.f1 % int4 '2') = int2 '0';
160 SELECT '' AS five, i.f1, i.f1 * int2 '2' AS x FROM INT4_TBL i;
161 ERROR: integer out of range
162 SELECT '' AS five, i.f1, i.f1 * int2 '2' AS x FROM INT4_TBL i
163 WHERE abs(f1) < 1073741824;
165 ------+---------+---------
171 SELECT '' AS five, i.f1, i.f1 * int4 '2' AS x FROM INT4_TBL i;
172 ERROR: integer out of range
173 SELECT '' AS five, i.f1, i.f1 * int4 '2' AS x FROM INT4_TBL i
174 WHERE abs(f1) < 1073741824;
176 ------+---------+---------
182 SELECT '' AS five, i.f1, i.f1 + int2 '2' AS x FROM INT4_TBL i;
183 ERROR: integer out of range
184 SELECT '' AS five, i.f1, i.f1 + int2 '2' AS x FROM INT4_TBL i
185 WHERE f1 < 2147483646;
187 ------+-------------+-------------
191 | -2147483647 | -2147483645
194 SELECT '' AS five, i.f1, i.f1 + int4 '2' AS x FROM INT4_TBL i;
195 ERROR: integer out of range
196 SELECT '' AS five, i.f1, i.f1 + int4 '2' AS x FROM INT4_TBL i
197 WHERE f1 < 2147483646;
199 ------+-------------+-------------
203 | -2147483647 | -2147483645
206 SELECT '' AS five, i.f1, i.f1 - int2 '2' AS x FROM INT4_TBL i;
207 ERROR: integer out of range
208 SELECT '' AS five, i.f1, i.f1 - int2 '2' AS x FROM INT4_TBL i
209 WHERE f1 > -2147483647;
211 ------+------------+------------
215 | 2147483647 | 2147483645
218 SELECT '' AS five, i.f1, i.f1 - int4 '2' AS x FROM INT4_TBL i;
219 ERROR: integer out of range
220 SELECT '' AS five, i.f1, i.f1 - int4 '2' AS x FROM INT4_TBL i
221 WHERE f1 > -2147483647;
223 ------+------------+------------
227 | 2147483647 | 2147483645
230 SELECT '' AS five, i.f1, i.f1 / int2 '2' AS x FROM INT4_TBL i;
232 ------+-------------+-------------
236 | 2147483647 | 1073741823
237 | -2147483647 | -1073741823
240 SELECT '' AS five, i.f1, i.f1 / int4 '2' AS x FROM INT4_TBL i;
242 ------+-------------+-------------
246 | 2147483647 | 1073741823
247 | -2147483647 | -1073741823
251 -- more complex expressions
253 -- variations on unary minus parsing
266 SELECT 2- -1 AS three;
272 SELECT 2 - -2 AS four;
278 SELECT int2 '2' * int2 '2' = int2 '16' / int2 '4' AS true;
284 SELECT int4 '2' * int2 '2' = int2 '16' / int4 '4' AS true;
290 SELECT int2 '2' * int4 '2' = int4 '16' / int2 '4' AS true;
296 SELECT int4 '1000' < int4 '999' AS false;
302 SELECT 4! AS twenty_four;
314 SELECT 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 AS ten;
320 SELECT 2 + 2 / 2 AS three;
326 SELECT (2 + 2) / 2 AS two;
333 SELECT (-1::int4<<31)::text;
339 SELECT ((-1::int4<<31)+1)::text;