Commit 4171bb86 authored by Tom Lane's avatar Tom Lane

Detect overflow in integer arithmetic operators (integer, smallint, and

bigint variants).  Clean up some inconsistencies in error message wording.
Fix scanint8 to allow trailing whitespace in INT64_MIN case.  Update
int8-exp-three-digits.out, which seems to have been ignored by the last
couple of people to modify the int8 regression test, and remove
int8-exp-three-digits-win32.out which is thereby exposed as redundant.
parent 24201b4b
<!-- <!--
$PostgreSQL: pgsql/doc/src/sgml/release.sgml,v 1.298 2004/10/01 02:00:43 neilc Exp $ $PostgreSQL: pgsql/doc/src/sgml/release.sgml,v 1.299 2004/10/04 14:42:46 tgl Exp $
--> -->
<appendix id="release"> <appendix id="release">
...@@ -256,6 +256,13 @@ $PostgreSQL: pgsql/doc/src/sgml/release.sgml,v 1.298 2004/10/01 02:00:43 neilc E ...@@ -256,6 +256,13 @@ $PostgreSQL: pgsql/doc/src/sgml/release.sgml,v 1.298 2004/10/01 02:00:43 neilc E
</para> </para>
</listitem> </listitem>
<listitem>
<para>
Overflow in integer arithmetic operations is now detected and
reported as an error.
</para>
</listitem>
<listitem> <listitem>
<para> <para>
The server now warns of empty strings passed to The server now warns of empty strings passed to
...@@ -1228,6 +1235,12 @@ $PostgreSQL: pgsql/doc/src/sgml/release.sgml,v 1.298 2004/10/01 02:00:43 neilc E ...@@ -1228,6 +1235,12 @@ $PostgreSQL: pgsql/doc/src/sgml/release.sgml,v 1.298 2004/10/01 02:00:43 neilc E
</para> </para>
</listitem> </listitem>
<listitem>
<para>
Overflow in integer arithmetic operations is now detected (Tom)
</para>
</listitem>
<listitem> <listitem>
<para> <para>
Syntax checking of array input values considerably tightened up (Joe) Syntax checking of array input values considerably tightened up (Joe)
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/float.c,v 1.110 2004/09/02 17:12:50 tgl Exp $ * $PostgreSQL: pgsql/src/backend/utils/adt/float.c,v 1.111 2004/10/04 14:42:46 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -1147,7 +1147,7 @@ dtoi2(PG_FUNCTION_ARGS) ...@@ -1147,7 +1147,7 @@ dtoi2(PG_FUNCTION_ARGS)
if ((num < SHRT_MIN) || (num > SHRT_MAX)) if ((num < SHRT_MIN) || (num > SHRT_MAX))
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("integer out of range"))); errmsg("smallint out of range")));
result = (int16) rint(num); result = (int16) rint(num);
PG_RETURN_INT16(result); PG_RETURN_INT16(result);
...@@ -1213,7 +1213,7 @@ ftoi2(PG_FUNCTION_ARGS) ...@@ -1213,7 +1213,7 @@ ftoi2(PG_FUNCTION_ARGS)
if ((num < SHRT_MIN) || (num > SHRT_MAX)) if ((num < SHRT_MIN) || (num > SHRT_MAX))
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("integer out of range"))); errmsg("smallint out of range")));
result = (int16) rint(num); result = (int16) rint(num);
PG_RETURN_INT16(result); PG_RETURN_INT16(result);
......
This diff is collapsed.
This diff is collapsed.
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
* Copyright (c) 1998-2004, PostgreSQL Global Development Group * Copyright (c) 1998-2004, PostgreSQL Global Development Group
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/numeric.c,v 1.79 2004/08/30 02:54:39 momjian Exp $ * $PostgreSQL: pgsql/src/backend/utils/adt/numeric.c,v 1.80 2004/10/04 14:42:46 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -1826,7 +1826,7 @@ numeric_int8(PG_FUNCTION_ARGS) ...@@ -1826,7 +1826,7 @@ numeric_int8(PG_FUNCTION_ARGS)
if (NUMERIC_IS_NAN(num)) if (NUMERIC_IS_NAN(num))
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED), (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot convert NaN to integer"))); errmsg("cannot convert NaN to bigint")));
/* Convert to variable format and thence to int8 */ /* Convert to variable format and thence to int8 */
init_var(&x); init_var(&x);
...@@ -1835,7 +1835,7 @@ numeric_int8(PG_FUNCTION_ARGS) ...@@ -1835,7 +1835,7 @@ numeric_int8(PG_FUNCTION_ARGS)
if (!numericvar_to_int8(&x, &result)) if (!numericvar_to_int8(&x, &result))
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("integer out of range"))); errmsg("bigint out of range")));
free_var(&x); free_var(&x);
...@@ -1874,7 +1874,7 @@ numeric_int2(PG_FUNCTION_ARGS) ...@@ -1874,7 +1874,7 @@ numeric_int2(PG_FUNCTION_ARGS)
if (NUMERIC_IS_NAN(num)) if (NUMERIC_IS_NAN(num))
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED), (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot convert NaN to integer"))); errmsg("cannot convert NaN to smallint")));
/* Convert to variable format and thence to int8 */ /* Convert to variable format and thence to int8 */
init_var(&x); init_var(&x);
...@@ -1883,7 +1883,7 @@ numeric_int2(PG_FUNCTION_ARGS) ...@@ -1883,7 +1883,7 @@ numeric_int2(PG_FUNCTION_ARGS)
if (!numericvar_to_int8(&x, &val)) if (!numericvar_to_int8(&x, &val))
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("integer out of range"))); errmsg("smallint out of range")));
free_var(&x); free_var(&x);
...@@ -1894,7 +1894,7 @@ numeric_int2(PG_FUNCTION_ARGS) ...@@ -1894,7 +1894,7 @@ numeric_int2(PG_FUNCTION_ARGS)
if ((int64) result != val) if ((int64) result != val)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("integer out of range"))); errmsg("smallint out of range")));
PG_RETURN_INT16(result); PG_RETURN_INT16(result);
} }
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/numutils.c,v 1.65 2004/08/29 05:06:49 momjian Exp $ * $PostgreSQL: pgsql/src/backend/utils/adt/numutils.c,v 1.66 2004/10/04 14:42:46 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -114,7 +114,7 @@ pg_atoi(char *s, int size, int c) ...@@ -114,7 +114,7 @@ pg_atoi(char *s, int size, int c)
if (errno == ERANGE || l < SHRT_MIN || l > SHRT_MAX) if (errno == ERANGE || l < SHRT_MIN || l > SHRT_MAX)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("value \"%s\" is out of range for type shortint", s))); errmsg("value \"%s\" is out of range for type smallint", s)));
break; break;
case sizeof(int8): case sizeof(int8):
if (errno == ERANGE || l < SCHAR_MIN || l > SCHAR_MAX) if (errno == ERANGE || l < SCHAR_MIN || l > SCHAR_MAX)
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/varbit.c,v 1.42 2004/08/29 05:06:49 momjian Exp $ * $PostgreSQL: pgsql/src/backend/utils/adt/varbit.c,v 1.43 2004/10/04 14:42:46 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -1310,7 +1310,7 @@ bittoint8(PG_FUNCTION_ARGS) ...@@ -1310,7 +1310,7 @@ bittoint8(PG_FUNCTION_ARGS)
if (VARBITLEN(arg) > sizeof(result) * BITS_PER_BYTE) if (VARBITLEN(arg) > sizeof(result) * BITS_PER_BYTE)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("integer out of range"))); errmsg("bigint out of range")));
result = 0; result = 0;
for (r = VARBITS(arg); r < VARBITEND(arg); r++) for (r = VARBITS(arg); r < VARBITEND(arg); r++)
......
...@@ -14,7 +14,7 @@ INSERT INTO INT2_TBL(f1) VALUES ('32767'); ...@@ -14,7 +14,7 @@ INSERT INTO INT2_TBL(f1) VALUES ('32767');
INSERT INTO INT2_TBL(f1) VALUES ('-32767'); INSERT INTO INT2_TBL(f1) VALUES ('-32767');
-- bad input values -- should give errors -- bad input values -- should give errors
INSERT INTO INT2_TBL(f1) VALUES ('100000'); INSERT INTO INT2_TBL(f1) VALUES ('100000');
ERROR: value "100000" is out of range for type shortint ERROR: value "100000" is out of range for type smallint
INSERT INTO INT2_TBL(f1) VALUES ('asdf'); INSERT INTO INT2_TBL(f1) VALUES ('asdf');
ERROR: invalid input syntax for integer: "asdf" ERROR: invalid input syntax for integer: "asdf"
INSERT INTO INT2_TBL(f1) VALUES (' '); INSERT INTO INT2_TBL(f1) VALUES (' ');
...@@ -144,14 +144,15 @@ SELECT '' AS three, i.* FROM INT2_TBL i WHERE (i.f1 % int4 '2') = int2 '0'; ...@@ -144,14 +144,15 @@ SELECT '' AS three, i.* FROM INT2_TBL i WHERE (i.f1 % int4 '2') = int2 '0';
(3 rows) (3 rows)
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;
ERROR: smallint out of range
SELECT '' AS five, i.f1, i.f1 * int2 '2' AS x FROM INT2_TBL i
WHERE abs(f1) < 16384;
five | f1 | x five | f1 | x
------+--------+------- ------+-------+-------
| 0 | 0 | 0 | 0
| 1234 | 2468 | 1234 | 2468
| -1234 | -2468 | -1234 | -2468
| 32767 | -2 (3 rows)
| -32767 | 2
(5 rows)
SELECT '' AS five, i.f1, i.f1 * int4 '2' AS x FROM INT2_TBL i; SELECT '' AS five, i.f1, i.f1 * int4 '2' AS x FROM INT2_TBL i;
five | f1 | x five | f1 | x
...@@ -164,14 +165,16 @@ SELECT '' AS five, i.f1, i.f1 * int4 '2' AS x FROM INT2_TBL i; ...@@ -164,14 +165,16 @@ SELECT '' AS five, i.f1, i.f1 * int4 '2' AS x FROM INT2_TBL i;
(5 rows) (5 rows)
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;
ERROR: smallint out of range
SELECT '' AS five, i.f1, i.f1 + int2 '2' AS x FROM INT2_TBL i
WHERE f1 < 32766;
five | f1 | x five | f1 | x
------+--------+-------- ------+--------+--------
| 0 | 2 | 0 | 2
| 1234 | 1236 | 1234 | 1236
| -1234 | -1232 | -1234 | -1232
| 32767 | -32767
| -32767 | -32765 | -32767 | -32765
(5 rows) (4 rows)
SELECT '' AS five, i.f1, i.f1 + int4 '2' AS x FROM INT2_TBL i; SELECT '' AS five, i.f1, i.f1 + int4 '2' AS x FROM INT2_TBL i;
five | f1 | x five | f1 | x
...@@ -184,14 +187,16 @@ SELECT '' AS five, i.f1, i.f1 + int4 '2' AS x FROM INT2_TBL i; ...@@ -184,14 +187,16 @@ SELECT '' AS five, i.f1, i.f1 + int4 '2' AS x FROM INT2_TBL i;
(5 rows) (5 rows)
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;
ERROR: smallint out of range
SELECT '' AS five, i.f1, i.f1 - int2 '2' AS x FROM INT2_TBL i
WHERE f1 > -32767;
five | f1 | x five | f1 | x
------+--------+------- ------+-------+-------
| 0 | -2 | 0 | -2
| 1234 | 1232 | 1234 | 1232
| -1234 | -1236 | -1234 | -1236
| 32767 | 32765 | 32767 | 32765
| -32767 | 32767 (4 rows)
(5 rows)
SELECT '' AS five, i.f1, i.f1 - int4 '2' AS x FROM INT2_TBL i; SELECT '' AS five, i.f1, i.f1 - int4 '2' AS x FROM INT2_TBL i;
five | f1 | x five | f1 | x
......
...@@ -144,64 +144,74 @@ SELECT '' AS three, i.* FROM INT4_TBL i WHERE (i.f1 % int4 '2') = int2 '0'; ...@@ -144,64 +144,74 @@ SELECT '' AS three, i.* FROM INT4_TBL i WHERE (i.f1 % int4 '2') = int2 '0';
(3 rows) (3 rows)
SELECT '' AS five, i.f1, i.f1 * int2 '2' AS x FROM INT4_TBL i; SELECT '' AS five, i.f1, i.f1 * int2 '2' AS x FROM INT4_TBL i;
ERROR: integer out of range
SELECT '' AS five, i.f1, i.f1 * int2 '2' AS x FROM INT4_TBL i
WHERE abs(f1) < 1073741824;
five | f1 | x five | f1 | x
------+-------------+--------- ------+---------+---------
| 0 | 0 | 0 | 0
| 123456 | 246912 | 123456 | 246912
| -123456 | -246912 | -123456 | -246912
| 2147483647 | -2 (3 rows)
| -2147483647 | 2
(5 rows)
SELECT '' AS five, i.f1, i.f1 * int4 '2' AS x FROM INT4_TBL i; SELECT '' AS five, i.f1, i.f1 * int4 '2' AS x FROM INT4_TBL i;
ERROR: integer out of range
SELECT '' AS five, i.f1, i.f1 * int4 '2' AS x FROM INT4_TBL i
WHERE abs(f1) < 1073741824;
five | f1 | x five | f1 | x
------+-------------+--------- ------+---------+---------
| 0 | 0 | 0 | 0
| 123456 | 246912 | 123456 | 246912
| -123456 | -246912 | -123456 | -246912
| 2147483647 | -2 (3 rows)
| -2147483647 | 2
(5 rows)
SELECT '' AS five, i.f1, i.f1 + int2 '2' AS x FROM INT4_TBL i; SELECT '' AS five, i.f1, i.f1 + int2 '2' AS x FROM INT4_TBL i;
ERROR: integer out of range
SELECT '' AS five, i.f1, i.f1 + int2 '2' AS x FROM INT4_TBL i
WHERE f1 < 2147483646;
five | f1 | x five | f1 | x
------+-------------+------------- ------+-------------+-------------
| 0 | 2 | 0 | 2
| 123456 | 123458 | 123456 | 123458
| -123456 | -123454 | -123456 | -123454
| 2147483647 | -2147483647
| -2147483647 | -2147483645 | -2147483647 | -2147483645
(5 rows) (4 rows)
SELECT '' AS five, i.f1, i.f1 + int4 '2' AS x FROM INT4_TBL i; SELECT '' AS five, i.f1, i.f1 + int4 '2' AS x FROM INT4_TBL i;
ERROR: integer out of range
SELECT '' AS five, i.f1, i.f1 + int4 '2' AS x FROM INT4_TBL i
WHERE f1 < 2147483646;
five | f1 | x five | f1 | x
------+-------------+------------- ------+-------------+-------------
| 0 | 2 | 0 | 2
| 123456 | 123458 | 123456 | 123458
| -123456 | -123454 | -123456 | -123454
| 2147483647 | -2147483647
| -2147483647 | -2147483645 | -2147483647 | -2147483645
(5 rows) (4 rows)
SELECT '' AS five, i.f1, i.f1 - int2 '2' AS x FROM INT4_TBL i; SELECT '' AS five, i.f1, i.f1 - int2 '2' AS x FROM INT4_TBL i;
ERROR: integer out of range
SELECT '' AS five, i.f1, i.f1 - int2 '2' AS x FROM INT4_TBL i
WHERE f1 > -2147483647;
five | f1 | x five | f1 | x
------+-------------+------------ ------+------------+------------
| 0 | -2 | 0 | -2
| 123456 | 123454 | 123456 | 123454
| -123456 | -123458 | -123456 | -123458
| 2147483647 | 2147483645 | 2147483647 | 2147483645
| -2147483647 | 2147483647 (4 rows)
(5 rows)
SELECT '' AS five, i.f1, i.f1 - int4 '2' AS x FROM INT4_TBL i; SELECT '' AS five, i.f1, i.f1 - int4 '2' AS x FROM INT4_TBL i;
ERROR: integer out of range
SELECT '' AS five, i.f1, i.f1 - int4 '2' AS x FROM INT4_TBL i
WHERE f1 > -2147483647;
five | f1 | x five | f1 | x
------+-------------+------------ ------+------------+------------
| 0 | -2 | 0 | -2
| 123456 | 123454 | 123456 | 123454
| -123456 | -123458 | -123456 | -123458
| 2147483647 | 2147483645 | 2147483647 | 2147483645
| -2147483647 | 2147483647 (4 rows)
(5 rows)
SELECT '' AS five, i.f1, i.f1 / int2 '2' AS x FROM INT4_TBL i; SELECT '' AS five, i.f1, i.f1 / int2 '2' AS x FROM INT4_TBL i;
five | f1 | x five | f1 | x
......
...@@ -3,11 +3,26 @@ ...@@ -3,11 +3,26 @@
-- Test int8 64-bit integers. -- Test int8 64-bit integers.
-- --
CREATE TABLE INT8_TBL(q1 int8, q2 int8); CREATE TABLE INT8_TBL(q1 int8, q2 int8);
INSERT INTO INT8_TBL VALUES('123','456'); INSERT INTO INT8_TBL VALUES(' 123 ',' 456');
INSERT INTO INT8_TBL VALUES('123','4567890123456789'); INSERT INTO INT8_TBL VALUES('123 ','4567890123456789');
INSERT INTO INT8_TBL VALUES('4567890123456789','123'); INSERT INTO INT8_TBL VALUES('4567890123456789','123');
INSERT INTO INT8_TBL VALUES('4567890123456789','4567890123456789'); INSERT INTO INT8_TBL VALUES('4567890123456789','4567890123456789');
INSERT INTO INT8_TBL VALUES('4567890123456789','-4567890123456789'); INSERT INTO INT8_TBL VALUES('4567890123456789','-4567890123456789');
-- bad inputs
INSERT INTO INT8_TBL(q1) VALUES (' ');
ERROR: invalid input syntax for integer: " "
INSERT INTO INT8_TBL(q1) VALUES ('xxx');
ERROR: invalid input syntax for integer: "xxx"
INSERT INTO INT8_TBL(q1) VALUES ('3908203590239580293850293850329485');
ERROR: value "3908203590239580293850293850329485" is out of range for type bigint
INSERT INTO INT8_TBL(q1) VALUES ('-1204982019841029840928340329840934');
ERROR: value "-1204982019841029840928340329840934" is out of range for type bigint
INSERT INTO INT8_TBL(q1) VALUES ('- 123');
ERROR: invalid input syntax for integer: "- 123"
INSERT INTO INT8_TBL(q1) VALUES (' 345 5');
ERROR: invalid input syntax for integer: " 345 5"
INSERT INTO INT8_TBL(q1) VALUES ('');
ERROR: invalid input syntax for integer: ""
SELECT * FROM INT8_TBL; SELECT * FROM INT8_TBL;
q1 | q2 q1 | q2
------------------+------------------- ------------------+-------------------
...@@ -48,6 +63,8 @@ SELECT '' AS five, q1, q2, q1 - q2 AS minus FROM INT8_TBL; ...@@ -48,6 +63,8 @@ SELECT '' AS five, q1, q2, q1 - q2 AS minus FROM INT8_TBL;
| 4567890123456789 | -4567890123456789 | 9135780246913578 | 4567890123456789 | -4567890123456789 | 9135780246913578
(5 rows) (5 rows)
SELECT '' AS three, q1, q2, q1 * q2 AS multiply FROM INT8_TBL;
ERROR: bigint out of range
SELECT '' AS three, q1, q2, q1 * q2 AS multiply FROM INT8_TBL SELECT '' AS three, q1, q2, q1 * q2 AS multiply FROM INT8_TBL
WHERE q1 < 1000 or (q2 > 0 and q2 < 1000); WHERE q1 < 1000 or (q2 > 0 and q2 < 1000);
three | q1 | q2 | multiply three | q1 | q2 | multiply
...@@ -155,7 +172,7 @@ SELECT '' AS to_char_4, to_char( (q1 * -1), '9999999999999999S'), to_char( (q2 * ...@@ -155,7 +172,7 @@ SELECT '' AS to_char_4, to_char( (q1 * -1), '9999999999999999S'), to_char( (q2 *
SELECT '' AS to_char_5, to_char(q2, 'MI9999999999999999') FROM INT8_TBL; SELECT '' AS to_char_5, to_char(q2, 'MI9999999999999999') FROM INT8_TBL;
to_char_5 | to_char to_char_5 | to_char
-----------+-------------------- -----------+-------------------
| 456 | 456
| 4567890123456789 | 4567890123456789
| 123 | 123
...@@ -257,10 +274,10 @@ SELECT '' AS to_char_15, to_char(q2, 'S 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 . 9 9 9' ...@@ -257,10 +274,10 @@ SELECT '' AS to_char_15, to_char(q2, 'S 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 . 9 9 9'
to_char_15 | to_char to_char_15 | to_char
------------+------------------------------------------- ------------+-------------------------------------------
| +4 5 6 . 0 0 0 | +4 5 6 . 0 0 0
| + 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 . 0 0 0 | +4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 . 0 0 0
| +1 2 3 . 0 0 0 | +1 2 3 . 0 0 0
| + 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 . 0 0 0 | +4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 . 0 0 0
| - 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 . 0 0 0 | -4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 . 0 0 0
(5 rows) (5 rows)
SELECT '' AS to_char_16, to_char(q2, '99999 "text" 9999 "9999" 999 "\\"text between quote marks\\"" 9999') FROM INT8_TBL; SELECT '' AS to_char_16, to_char(q2, '99999 "text" 9999 "9999" 999 "\\"text between quote marks\\"" 9999') FROM INT8_TBL;
......
...@@ -10,19 +10,19 @@ INSERT INTO INT8_TBL VALUES('4567890123456789','4567890123456789'); ...@@ -10,19 +10,19 @@ INSERT INTO INT8_TBL VALUES('4567890123456789','4567890123456789');
INSERT INTO INT8_TBL VALUES('4567890123456789','-4567890123456789'); INSERT INTO INT8_TBL VALUES('4567890123456789','-4567890123456789');
-- bad inputs -- bad inputs
INSERT INTO INT8_TBL(q1) VALUES (' '); INSERT INTO INT8_TBL(q1) VALUES (' ');
ERROR: invalid input syntax for type bigint: " " ERROR: invalid input syntax for integer: " "
INSERT INTO INT8_TBL(q1) VALUES ('xxx'); INSERT INTO INT8_TBL(q1) VALUES ('xxx');
ERROR: invalid input syntax for type bigint: "xxx" ERROR: invalid input syntax for integer: "xxx"
INSERT INTO INT8_TBL(q1) VALUES ('3908203590239580293850293850329485'); INSERT INTO INT8_TBL(q1) VALUES ('3908203590239580293850293850329485');
ERROR: integer out of range ERROR: value "3908203590239580293850293850329485" is out of range for type bigint
INSERT INTO INT8_TBL(q1) VALUES ('-1204982019841029840928340329840934'); INSERT INTO INT8_TBL(q1) VALUES ('-1204982019841029840928340329840934');
ERROR: integer out of range ERROR: value "-1204982019841029840928340329840934" is out of range for type bigint
INSERT INTO INT8_TBL(q1) VALUES ('- 123'); INSERT INTO INT8_TBL(q1) VALUES ('- 123');
ERROR: invalid input syntax for type bigint: "- 123" ERROR: invalid input syntax for integer: "- 123"
INSERT INTO INT8_TBL(q1) VALUES (' 345 5'); INSERT INTO INT8_TBL(q1) VALUES (' 345 5');
ERROR: invalid input syntax for type bigint: " 345 5" ERROR: invalid input syntax for integer: " 345 5"
INSERT INTO INT8_TBL(q1) VALUES (''); INSERT INTO INT8_TBL(q1) VALUES ('');
ERROR: invalid input syntax for type bigint: "" ERROR: invalid input syntax for integer: ""
SELECT * FROM INT8_TBL; SELECT * FROM INT8_TBL;
q1 | q2 q1 | q2
------------------+------------------- ------------------+-------------------
...@@ -63,6 +63,8 @@ SELECT '' AS five, q1, q2, q1 - q2 AS minus FROM INT8_TBL; ...@@ -63,6 +63,8 @@ SELECT '' AS five, q1, q2, q1 - q2 AS minus FROM INT8_TBL;
| 4567890123456789 | -4567890123456789 | 9135780246913578 | 4567890123456789 | -4567890123456789 | 9135780246913578
(5 rows) (5 rows)
SELECT '' AS three, q1, q2, q1 * q2 AS multiply FROM INT8_TBL;
ERROR: bigint out of range
SELECT '' AS three, q1, q2, q1 * q2 AS multiply FROM INT8_TBL SELECT '' AS three, q1, q2, q1 * q2 AS multiply FROM INT8_TBL
WHERE q1 < 1000 or (q2 > 0 and q2 < 1000); WHERE q1 < 1000 or (q2 > 0 and q2 < 1000);
three | q1 | q2 | multiply three | q1 | q2 | multiply
......
...@@ -146,7 +146,8 @@ SELECT '' AS five, f1 AS "Correlated Field" ...@@ -146,7 +146,8 @@ SELECT '' AS five, f1 AS "Correlated Field"
-- --
SELECT '' AS eight, ss.f1 AS "Correlated Field", ss.f3 AS "Second Field" SELECT '' AS eight, ss.f1 AS "Correlated Field", ss.f3 AS "Second Field"
FROM SUBSELECT_TBL ss FROM SUBSELECT_TBL ss
WHERE f1 NOT IN (SELECT f1+1 FROM INT4_TBL WHERE f1 != ss.f1); WHERE f1 NOT IN (SELECT f1+1 FROM INT4_TBL
WHERE f1 != ss.f1 AND f1 < 2147483647);
eight | Correlated Field | Second Field eight | Correlated Field | Second Field
-------+------------------+-------------- -------+------------------+--------------
| 2 | 4 | 2 | 4
......
...@@ -7,4 +7,4 @@ float8/.*-qnx=float8-exp-three-digits ...@@ -7,4 +7,4 @@ float8/.*-qnx=float8-exp-three-digits
float8/i.86-pc-mingw32=float8-exp-three-digits-win32 float8/i.86-pc-mingw32=float8-exp-three-digits-win32
float8/i.86-pc-cygwin=float8-small-is-zero float8/i.86-pc-cygwin=float8-small-is-zero
int8/.*-qnx=int8-exp-three-digits int8/.*-qnx=int8-exp-three-digits
int8/i.86-pc-mingw32=int8-exp-three-digits-win32 int8/i.86-pc-mingw32=int8-exp-three-digits
...@@ -63,14 +63,23 @@ SELECT '' AS three, i.* FROM INT2_TBL i WHERE (i.f1 % int4 '2') = int2 '0'; ...@@ -63,14 +63,23 @@ 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;
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 * 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;
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 + 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;
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 - 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;
......
...@@ -63,16 +63,34 @@ SELECT '' AS three, i.* FROM INT4_TBL i WHERE (i.f1 % int4 '2') = int2 '0'; ...@@ -63,16 +63,34 @@ SELECT '' AS three, i.* FROM INT4_TBL i WHERE (i.f1 % int4 '2') = int2 '0';
SELECT '' AS five, i.f1, i.f1 * int2 '2' AS x FROM INT4_TBL i; SELECT '' AS five, i.f1, i.f1 * int2 '2' AS x FROM INT4_TBL i;
SELECT '' AS five, i.f1, i.f1 * int2 '2' AS x FROM INT4_TBL i
WHERE abs(f1) < 1073741824;
SELECT '' AS five, i.f1, i.f1 * int4 '2' AS x FROM INT4_TBL i; SELECT '' AS five, i.f1, i.f1 * int4 '2' AS x FROM INT4_TBL i;
SELECT '' AS five, i.f1, i.f1 * int4 '2' AS x FROM INT4_TBL i
WHERE abs(f1) < 1073741824;
SELECT '' AS five, i.f1, i.f1 + int2 '2' AS x FROM INT4_TBL i; SELECT '' AS five, i.f1, i.f1 + int2 '2' AS x FROM INT4_TBL i;
SELECT '' AS five, i.f1, i.f1 + int2 '2' AS x FROM INT4_TBL i
WHERE f1 < 2147483646;
SELECT '' AS five, i.f1, i.f1 + int4 '2' AS x FROM INT4_TBL i; SELECT '' AS five, i.f1, i.f1 + int4 '2' AS x FROM INT4_TBL i;
SELECT '' AS five, i.f1, i.f1 + int4 '2' AS x FROM INT4_TBL i
WHERE f1 < 2147483646;
SELECT '' AS five, i.f1, i.f1 - int2 '2' AS x FROM INT4_TBL i; SELECT '' AS five, i.f1, i.f1 - int2 '2' AS x FROM INT4_TBL i;
SELECT '' AS five, i.f1, i.f1 - int2 '2' AS x FROM INT4_TBL i
WHERE f1 > -2147483647;
SELECT '' AS five, i.f1, i.f1 - int4 '2' AS x FROM INT4_TBL i; SELECT '' AS five, i.f1, i.f1 - int4 '2' AS x FROM INT4_TBL i;
SELECT '' AS five, i.f1, i.f1 - int4 '2' AS x FROM INT4_TBL i
WHERE f1 > -2147483647;
SELECT '' AS five, i.f1, i.f1 / int2 '2' AS x FROM INT4_TBL i; SELECT '' AS five, i.f1, i.f1 / int2 '2' AS x FROM INT4_TBL i;
SELECT '' AS five, i.f1, i.f1 / int4 '2' AS x FROM INT4_TBL i; SELECT '' AS five, i.f1, i.f1 / int4 '2' AS x FROM INT4_TBL i;
......
...@@ -25,6 +25,7 @@ SELECT '' AS five, q1 AS plus, -q1 AS minus FROM INT8_TBL; ...@@ -25,6 +25,7 @@ SELECT '' AS five, q1 AS plus, -q1 AS minus FROM INT8_TBL;
SELECT '' AS five, q1, q2, q1 + q2 AS plus FROM INT8_TBL; SELECT '' AS five, q1, q2, q1 + q2 AS plus FROM INT8_TBL;
SELECT '' AS five, q1, q2, q1 - q2 AS minus FROM INT8_TBL; SELECT '' AS five, q1, q2, q1 - q2 AS minus FROM INT8_TBL;
SELECT '' AS three, q1, q2, q1 * q2 AS multiply FROM INT8_TBL;
SELECT '' AS three, q1, q2, q1 * q2 AS multiply FROM INT8_TBL SELECT '' AS three, q1, q2, q1 * q2 AS multiply FROM INT8_TBL
WHERE q1 < 1000 or (q2 > 0 and q2 < 1000); WHERE q1 < 1000 or (q2 > 0 and q2 < 1000);
SELECT '' AS five, q1, q2, q1 / q2 AS divide FROM INT8_TBL; SELECT '' AS five, q1, q2, q1 / q2 AS divide FROM INT8_TBL;
......
...@@ -71,7 +71,8 @@ SELECT '' AS five, f1 AS "Correlated Field" ...@@ -71,7 +71,8 @@ SELECT '' AS five, f1 AS "Correlated Field"
SELECT '' AS eight, ss.f1 AS "Correlated Field", ss.f3 AS "Second Field" SELECT '' AS eight, ss.f1 AS "Correlated Field", ss.f3 AS "Second Field"
FROM SUBSELECT_TBL ss FROM SUBSELECT_TBL ss
WHERE f1 NOT IN (SELECT f1+1 FROM INT4_TBL WHERE f1 != ss.f1); WHERE f1 NOT IN (SELECT f1+1 FROM INT4_TBL
WHERE f1 != ss.f1 AND f1 < 2147483647);
select q1, float8(count(*)) / (select count(*) from int8_tbl) select q1, float8(count(*)) / (select count(*) from int8_tbl)
from int8_tbl group by q1 order by q1; from int8_tbl group by q1 order by q1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment