Bug #8423 Traditional: Division by 0 returns NULL
Submitted: 10 Feb 2005 20:54 Modified: 9 Jan 2014 13:33
Reporter: Trudy Pelzer Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Errors Severity:S3 (Non-critical)
Version:5.0.3-alpha-debug OS:Linux (SuSE 9.1)
Assigned to: Assigned Account CPU Architecture:Any

[10 Feb 2005 20:54] Trudy Pelzer
Description:
When sql_mode='traditional', all "divide by 0" operations
must fail with SQLSTATE 22012 division by zero. This
used to work correctly (except with MOD, see related
Bug #5929) but, since the push of the precision math
code, the server now returns NULL instead of a failure.

How to repeat:
mysql> set sql_mode=traditional;
Query OK, 0 rows affected (0.00 sec)

mysql> create table t (col1 int, col2 decimal(10,3), col3 numeric(10,3));
Query OK, 0 rows affected (0.00 sec)

mysql> insert into t values (1,123.456,123.456);
Query OK, 1 row affected (0.00 sec)

mysql> select col1/0 from t;
+--------+
| col1/0 |
+--------+
| NULL   |
+--------+
1 row in set, 1 warning (0.00 sec)
-- This is not the expected result. This operation should
fail, and return SQLSTATE 22012 division by zero.

mysql> select col2/0 from t;
+--------+
| col2/0 |
+--------+
| NULL   |
+--------+
1 row in set, 1 warning (0.00 sec)
-- This is not the expected result. This operation should
fail, and return SQLSTATE 22012 division by zero.

mysql> select col3/0 from t;
+--------+
| col3/0 |
+--------+
| NULL   |
+--------+
1 row in set, 1 warning (0.00 sec)
-- This is not the expected result. This operation should
fail, and return SQLSTATE 22012 division by zero.
[10 Feb 2005 21:02] MySQL Verification Team
Thank you for the bug report.
[22 Feb 2005 8:59] Alexey Botchkov
bk commit - 5.0 tree (hf:1.1882) BUG#8423
[22 Feb 2005 13:24] Alexey Botchkov
decision was made to fix that in 5.1
[9 Jan 2014 13:33] Erlend Dahl
This behaviour is still present.

Moving to 'verified' since we are discontinuing the use of 'to be fixed later'.
[11 Nov 2017 21:16] Federico Razzoli
Identical results in 8.0.3.