mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-09-12 19:17:54 +02:00
1f7cb5c309
Some platforms throw an exception for this division, rather than returning a necessarily-overflowed result. Since we were testing for overflow after the fact, an exception isn't nice. We can avoid the problem by treating division by -1 as negation. Add some regression tests so that we'll find out if any compilers try to optimize away the overflow check conditions. This ought to be back-patched, but I'm going to see what the buildfarm reports about the regression tests first. Per discussion with Xi Wang, though this is different from the patch he submitted.
95 lines
2.6 KiB
SQL
95 lines
2.6 KiB
SQL
--
|
|
-- INT2
|
|
--
|
|
|
|
CREATE TABLE INT2_TBL(f1 int2);
|
|
|
|
INSERT INTO INT2_TBL(f1) VALUES ('0 ');
|
|
|
|
INSERT INTO INT2_TBL(f1) VALUES (' 1234 ');
|
|
|
|
INSERT INTO INT2_TBL(f1) VALUES (' -1234');
|
|
|
|
INSERT INTO INT2_TBL(f1) VALUES ('34.5');
|
|
|
|
-- largest and smallest values
|
|
INSERT INTO INT2_TBL(f1) VALUES ('32767');
|
|
|
|
INSERT INTO INT2_TBL(f1) VALUES ('-32767');
|
|
|
|
-- bad input values -- should give errors
|
|
INSERT INTO INT2_TBL(f1) VALUES ('100000');
|
|
INSERT INTO INT2_TBL(f1) VALUES ('asdf');
|
|
INSERT INTO INT2_TBL(f1) VALUES (' ');
|
|
INSERT INTO INT2_TBL(f1) VALUES ('- 1234');
|
|
INSERT INTO INT2_TBL(f1) VALUES ('4 444');
|
|
INSERT INTO INT2_TBL(f1) VALUES ('123 dt');
|
|
INSERT INTO INT2_TBL(f1) VALUES ('');
|
|
|
|
|
|
SELECT '' AS five, * FROM INT2_TBL;
|
|
|
|
SELECT '' AS four, i.* FROM INT2_TBL i WHERE i.f1 <> int2 '0';
|
|
|
|
SELECT '' AS four, i.* FROM INT2_TBL i WHERE i.f1 <> int4 '0';
|
|
|
|
SELECT '' AS one, i.* FROM INT2_TBL i WHERE i.f1 = int2 '0';
|
|
|
|
SELECT '' AS one, i.* FROM INT2_TBL i WHERE i.f1 = int4 '0';
|
|
|
|
SELECT '' AS two, i.* FROM INT2_TBL i WHERE i.f1 < int2 '0';
|
|
|
|
SELECT '' AS two, i.* FROM INT2_TBL i WHERE i.f1 < int4 '0';
|
|
|
|
SELECT '' AS three, i.* FROM INT2_TBL i WHERE i.f1 <= int2 '0';
|
|
|
|
SELECT '' AS three, i.* FROM INT2_TBL i WHERE i.f1 <= int4 '0';
|
|
|
|
SELECT '' AS two, i.* FROM INT2_TBL i WHERE i.f1 > int2 '0';
|
|
|
|
SELECT '' AS two, i.* FROM INT2_TBL i WHERE i.f1 > int4 '0';
|
|
|
|
SELECT '' AS three, i.* FROM INT2_TBL i WHERE i.f1 >= int2 '0';
|
|
|
|
SELECT '' AS three, i.* FROM INT2_TBL i WHERE i.f1 >= int4 '0';
|
|
|
|
-- positive odds
|
|
SELECT '' AS one, i.* FROM INT2_TBL i WHERE (i.f1 % int2 '2') = int2 '1';
|
|
|
|
-- any evens
|
|
SELECT '' AS three, i.* FROM INT2_TBL i WHERE (i.f1 % int4 '2') = int2 '0';
|
|
|
|
SELECT '' AS five, i.f1, i.f1 * int2 '2' AS x FROM INT2_TBL i;
|
|
|
|
SELECT '' AS five, i.f1, i.f1 * int2 '2' AS x FROM INT2_TBL i
|
|
WHERE abs(f1) < 16384;
|
|
|
|
SELECT '' AS five, i.f1, i.f1 * int4 '2' AS x FROM INT2_TBL i;
|
|
|
|
SELECT '' AS five, i.f1, i.f1 + int2 '2' AS x FROM INT2_TBL i;
|
|
|
|
SELECT '' AS five, i.f1, i.f1 + int2 '2' AS x FROM INT2_TBL i
|
|
WHERE f1 < 32766;
|
|
|
|
SELECT '' AS five, i.f1, i.f1 + int4 '2' AS x FROM INT2_TBL i;
|
|
|
|
SELECT '' AS five, i.f1, i.f1 - int2 '2' AS x FROM INT2_TBL i;
|
|
|
|
SELECT '' AS five, i.f1, i.f1 - int2 '2' AS x FROM INT2_TBL i
|
|
WHERE f1 > -32767;
|
|
|
|
SELECT '' AS five, i.f1, i.f1 - int4 '2' AS x FROM INT2_TBL i;
|
|
|
|
SELECT '' AS five, i.f1, i.f1 / int2 '2' AS x FROM INT2_TBL i;
|
|
|
|
SELECT '' AS five, i.f1, i.f1 / int4 '2' AS x FROM INT2_TBL i;
|
|
|
|
-- corner cases
|
|
SELECT (-1::int2<<15)::text;
|
|
SELECT ((-1::int2<<15)+1::int2)::text;
|
|
|
|
-- check sane handling of INT16_MIN overflow cases
|
|
SELECT (-32768)::int2 * (-1)::int2;
|
|
SELECT (-32768)::int2 / (-1)::int2;
|
|
SELECT (-32768)::int2 % (-1)::int2;
|