diff options
| author | Tom Lane | 2003-03-11 21:01:33 +0000 |
|---|---|---|
| committer | Tom Lane | 2003-03-11 21:01:33 +0000 |
| commit | 31e69ccb210cf49712f77facbf90661d8bc2eed5 (patch) | |
| tree | ec6e0c1a656051db532cdef53a84309d6180c4a1 /src/test | |
| parent | 6261c75014c9948837d9d025493ef18b8f833f70 (diff) | |
Add explicit tests for division by zero to all user-accessible integer
division and modulo functions, to avoid problems on OS X (which fails to
trap 0 divide at all) and Windows (which traps it in some bizarre
nonstandard fashion). Standardize on 'division by zero' as the one true
spelling of this error message. Add regression tests as suggested by
Neil Conway.
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/regress/expected/errors.out | 41 | ||||
| -rw-r--r-- | src/test/regress/expected/float4-exp-three-digits.out | 2 | ||||
| -rw-r--r-- | src/test/regress/expected/float4.out | 2 | ||||
| -rw-r--r-- | src/test/regress/expected/float8-exp-three-digits.out | 2 | ||||
| -rw-r--r-- | src/test/regress/expected/float8-fp-exception.out | 2 | ||||
| -rw-r--r-- | src/test/regress/expected/float8-small-is-zero.out | 2 | ||||
| -rw-r--r-- | src/test/regress/expected/float8.out | 2 | ||||
| -rw-r--r-- | src/test/regress/sql/errors.sql | 42 |
8 files changed, 72 insertions, 23 deletions
diff --git a/src/test/regress/expected/errors.out b/src/test/regress/expected/errors.out index 698ccc85654..6c386292176 100644 --- a/src/test/regress/expected/errors.out +++ b/src/test/regress/expected/errors.out @@ -18,7 +18,7 @@ select 1; -- notify pg_class -- -- --- RETRIEVE +-- SELECT -- missing relation name select; @@ -54,7 +54,7 @@ ERROR: parser: parse error at or near ";" at character 12 delete from nonesuch; ERROR: Relation "nonesuch" does not exist -- --- DESTROY +-- DROP -- missing relation name (this had better not wildcard!) drop table; @@ -63,7 +63,7 @@ ERROR: parser: parse error at or near ";" at character 11 drop table nonesuch; ERROR: table "nonesuch" does not exist -- --- RENAME +-- ALTER TABLE -- relation renaming -- missing relation name @@ -104,7 +104,7 @@ WARNING: ROLLBACK: no transaction in progress end; WARNING: COMMIT: no transaction in progress -- --- DEFINE AGGREGATE +-- CREATE AGGREGATE -- sfunc/finalfunc type disagreement create aggregate newavg2 (sfunc = int4pl, basetype = int4, @@ -118,7 +118,7 @@ create aggregate newcnt1 (sfunc = int4inc, initcond = '0'); ERROR: Define: "basetype" unspecified -- --- REMOVE INDEX +-- DROP INDEX -- missing index name drop index; @@ -130,7 +130,7 @@ ERROR: parser: parse error at or near "314159" at character 12 drop index nonesuch; ERROR: index "nonesuch" does not exist -- --- REMOVE AGGREGATE +-- DROP AGGREGATE -- missing aggregate name drop aggregate; @@ -151,7 +151,7 @@ ERROR: RemoveAggregate: aggregate nonesuch(integer) does not exist drop aggregate newcnt (float4); ERROR: RemoveAggregate: aggregate newcnt(real) does not exist -- --- REMOVE FUNCTION +-- DROP FUNCTION -- missing function name drop function (); @@ -163,7 +163,7 @@ ERROR: parser: parse error at or near "314159" at character 15 drop function nonesuch(); ERROR: RemoveFunction: function nonesuch() does not exist -- --- REMOVE TYPE +-- DROP TYPE -- missing type name drop type; @@ -237,3 +237,28 @@ ERROR: parser: parse error at or near "instance" at character 6 -- no such rule drop rewrite rule nonesuch; ERROR: parser: parse error at or near "rewrite" at character 6 +-- +-- Check that division-by-zero is properly caught. +-- +select 1/0; +ERROR: division by zero +select 1::int8/0; +ERROR: division by zero +select 1/0::int8; +ERROR: division by zero +select 1::int2/0; +ERROR: division by zero +select 1/0::int2; +ERROR: division by zero +select 1::numeric/0; +ERROR: division by zero +select 1/0::numeric; +ERROR: division by zero +select 1::float8/0; +ERROR: division by zero +select 1/0::float8; +ERROR: division by zero +select 1::float4/0; +ERROR: division by zero +select 1/0::float4; +ERROR: division by zero diff --git a/src/test/regress/expected/float4-exp-three-digits.out b/src/test/regress/expected/float4-exp-three-digits.out index 8efd434a85f..72751ae29e9 100644 --- a/src/test/regress/expected/float4-exp-three-digits.out +++ b/src/test/regress/expected/float4-exp-three-digits.out @@ -113,7 +113,7 @@ SELECT '' AS three, f.f1, f.f1 - '-10' AS x FROM FLOAT4_TBL f -- test divide by zero SELECT '' AS bad, f.f1 / '0.0' from FLOAT4_TBL f; -ERROR: float4div: divide by zero error +ERROR: division by zero SELECT '' AS five, FLOAT4_TBL.*; five | f1 ------+-------------- diff --git a/src/test/regress/expected/float4.out b/src/test/regress/expected/float4.out index e03db639c5c..7ec463b7f31 100644 --- a/src/test/regress/expected/float4.out +++ b/src/test/regress/expected/float4.out @@ -113,7 +113,7 @@ SELECT '' AS three, f.f1, f.f1 - '-10' AS x FROM FLOAT4_TBL f -- test divide by zero SELECT '' AS bad, f.f1 / '0.0' from FLOAT4_TBL f; -ERROR: float4div: divide by zero error +ERROR: division by zero SELECT '' AS five, FLOAT4_TBL.*; five | f1 ------+------------- diff --git a/src/test/regress/expected/float8-exp-three-digits.out b/src/test/regress/expected/float8-exp-three-digits.out index b346ed5c38f..9d38aee1961 100644 --- a/src/test/regress/expected/float8-exp-three-digits.out +++ b/src/test/regress/expected/float8-exp-three-digits.out @@ -257,7 +257,7 @@ ERROR: can't take log of a negative number SELECT '' AS bad, exp(f.f1) from FLOAT8_TBL f; ERROR: exp() result is out of range SELECT '' AS bad, f.f1 / '0.0' from FLOAT8_TBL f; -ERROR: float8div: divide by zero error +ERROR: division by zero SELECT '' AS five, FLOAT8_TBL.*; five | f1 ------+----------------------- diff --git a/src/test/regress/expected/float8-fp-exception.out b/src/test/regress/expected/float8-fp-exception.out index 15d96ff365d..5c2df1e7c01 100644 --- a/src/test/regress/expected/float8-fp-exception.out +++ b/src/test/regress/expected/float8-fp-exception.out @@ -257,7 +257,7 @@ ERROR: can't take log of a negative number SELECT '' AS bad, exp(f.f1) from FLOAT8_TBL f; ERROR: exp() result is out of range SELECT '' AS bad, f.f1 / '0.0' from FLOAT8_TBL f; -ERROR: float8div: divide by zero error +ERROR: division by zero SELECT '' AS five, FLOAT8_TBL.*; five | f1 ------+----------------------- diff --git a/src/test/regress/expected/float8-small-is-zero.out b/src/test/regress/expected/float8-small-is-zero.out index 119051f3993..448bfc40bc2 100644 --- a/src/test/regress/expected/float8-small-is-zero.out +++ b/src/test/regress/expected/float8-small-is-zero.out @@ -257,7 +257,7 @@ ERROR: can't take log of a negative number SELECT '' AS bad, exp(f.f1) from FLOAT8_TBL f; ERROR: exp() result is out of range SELECT '' AS bad, f.f1 / '0.0' from FLOAT8_TBL f; -ERROR: float8div: divide by zero error +ERROR: division by zero SELECT '' AS five, FLOAT8_TBL.*; five | f1 ------+----------------------- diff --git a/src/test/regress/expected/float8.out b/src/test/regress/expected/float8.out index d91427c6ffa..576768785fd 100644 --- a/src/test/regress/expected/float8.out +++ b/src/test/regress/expected/float8.out @@ -257,7 +257,7 @@ ERROR: can't take log of a negative number SELECT '' AS bad, exp(f.f1) from FLOAT8_TBL f; ERROR: exp() result is out of range SELECT '' AS bad, f.f1 / '0.0' from FLOAT8_TBL f; -ERROR: float8div: divide by zero error +ERROR: division by zero SELECT '' AS five, FLOAT8_TBL.*; five | f1 ------+----------------------- diff --git a/src/test/regress/sql/errors.sql b/src/test/regress/sql/errors.sql index dee19bc136f..5876244ee3b 100644 --- a/src/test/regress/sql/errors.sql +++ b/src/test/regress/sql/errors.sql @@ -17,7 +17,7 @@ select 1; -- -- --- RETRIEVE +-- SELECT -- missing relation name select; @@ -55,7 +55,7 @@ delete from nonesuch; -- --- DESTROY +-- DROP -- missing relation name (this had better not wildcard!) drop table; @@ -65,9 +65,8 @@ drop table nonesuch; -- --- RENAME +-- ALTER TABLE - -- relation renaming -- missing relation name @@ -112,7 +111,7 @@ end; -- --- DEFINE AGGREGATE +-- CREATE AGGREGATE -- sfunc/finalfunc type disagreement create aggregate newavg2 (sfunc = int4pl, @@ -128,7 +127,7 @@ create aggregate newcnt1 (sfunc = int4inc, -- --- REMOVE INDEX +-- DROP INDEX -- missing index name drop index; @@ -141,7 +140,7 @@ drop index nonesuch; -- --- REMOVE AGGREGATE +-- DROP AGGREGATE -- missing aggregate name drop aggregate; @@ -163,7 +162,7 @@ drop aggregate newcnt (float4); -- --- REMOVE FUNCTION +-- DROP FUNCTION -- missing function name drop function (); @@ -176,7 +175,7 @@ drop function nonesuch(); -- --- REMOVE TYPE +-- DROP TYPE -- missing type name drop type; @@ -252,3 +251,28 @@ drop instance rule nonesuch on noplace; -- no such rule drop rewrite rule nonesuch; +-- +-- Check that division-by-zero is properly caught. +-- + +select 1/0; + +select 1::int8/0; + +select 1/0::int8; + +select 1::int2/0; + +select 1/0::int2; + +select 1::numeric/0; + +select 1/0::numeric; + +select 1::float8/0; + +select 1/0::float8; + +select 1::float4/0; + +select 1/0::float4; |
