Bug #16285 | NO_UNSIGNED_SUBTRACTION and subtraction of -1 from unsigned int problem | ||
---|---|---|---|
Submitted: | 8 Jan 2006 17:25 | Modified: | 31 Aug 2006 23:22 |
Reporter: | Andy Rigby | Email Updates: | |
Status: | Not a Bug | Impact on me: | |
Category: | MySQL Server | Severity: | S3 (Non-critical) |
Version: | 5.0.19-BK, 5.0.17 | OS: | Linux (Linux) |
Assigned to: | Bugs System | CPU Architecture: | Any |
[8 Jan 2006 17:25]
Andy Rigby
[10 Jan 2006 9:33]
Valeriy Kravchuk
Thank you for a bug report. Verified just as described on 5.0.19-BK (ChangeSet@1.2020, 2006-01-06 08:34:55-08:00) on Linux.
[31 Aug 2006 23:16]
Vladimir Shebordaev
This issue should not be considered as a bug. We ALWAYS get SIGNED value as a result of subtraction in NO_UNSIGNED_SUBTRACTION mode mysql> drop table if exists test; Query OK, 0 rows affected (0.00 sec) mysql> CREATE TABLE `test` (`myint` SMALLINT UNSIGNED NOT NULL); Query OK, 0 rows affected (0.02 sec) mysql> set sql_mode=''; Query OK, 0 rows affected (0.00 sec) mysql> CREATE TABLE t1 AS SELECT myint - 1 FROM test; Query OK, 0 rows affected (0.01 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> describe t1; +-----------+---------------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-----------+---------------------+------+-----+---------+-------+ | myint - 1 | bigint(17) unsigned | | | 0 | | +-----------+---------------------+------+-----+---------+-------+ 1 row in set (0.00 sec) mysql> set sql_mode='NO_UNSIGNED_SUBTRACTION'; Query OK, 0 rows affected (0.00 sec) mysql> CREATE TABLE t2 AS SELECT myint - 1 FROM test; Query OK, 0 rows affected (0.02 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> describe t2; +-----------+------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-----------+------------+------+-----+---------+-------+ | myint - 1 | bigint(17) | | | 0 | | +-----------+------------+------+-----+---------+-------+ 1 row in set (0.00 sec) mysql> CREATE TABLE t3 AS SELECT myint + 1 FROM test; Query OK, 0 rows affected (0.02 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> describe t3; +-----------+---------------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-----------+---------------------+------+-----+---------+-------+ | myint + 1 | bigint(17) unsigned | | | 0 | | +-----------+---------------------+------+-----+---------+-------+ 1 row in set (0.00 sec) So, the wrapped around/out of range values in the bug report are handled in full concert with that the section 11.2. "Numeric Types" of the Manual says at its very end. Thanks to Peter Gulutzan for clarification. The request for update of the section 5.2.5. "The Server SQL Mode" of the Manual has been sent. See also BUG#15472.
[1 Sep 2006 8:07]
Jon Stephens
Manual updated per Vladimir's email.