[MDEV-9334] ALTER from DECIMAL to BIGINT UNSIGNED returns a wrong result Created: 2015-12-28  Updated: 2018-06-15  Resolved: 2018-06-15

Status: Closed
Project: MariaDB Server
Component/s: OTHER
Affects Version/s: 5.5, 10.0, 10.1, 10.2
Fix Version/s: 10.2.16, 10.3.8, 10.4.0

Type: Bug Priority: Major
Reporter: Alexander Barkov Assignee: Alexander Barkov
Resolution: Fixed Votes: 1
Labels: None

Issue Links:
Blocks
blocks MDEV-4912 Data type plugin API version 1 Closed

 Description   

DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (a DECIMAL(30,0));
INSERT INTO t1 VALUES (CAST(0xFFFFFFFFFFFFFFFF AS UNSIGNED));
SELECT * FROM t1;

returns

+----------------------+
| a                    |
+----------------------+
| 18446744073709551615 |
+----------------------+

So far so good.

Now if I do:

ALTER TABLE t1 MODIFY a BIGINT UNSIGNED;
SELECT * FROM t1;

it erroneously returns:

+---------------------+
| a                   |
+---------------------+
| 9223372036854775807 |
+---------------------+

The expected result is 18446744073709551615.



 Comments   
Comment by Alexander Barkov [ 2018-06-15 ]

The same problem is repeatable with BIT(64)

SET sql_mode='';
DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (a DECIMAL(30,0));
INSERT INTO t1 VALUES (CAST(0xFFFFFFFFFFFFFFFF AS UNSIGNED));
ALTER TABLE t1 MODIFY a BIT(64);
SHOW WARNINGS;
SELECT a+0 FROM t1;

+---------+------+-----------------------------------------------------------------------------+
| Level   | Code | Message                                                                     |
+---------+------+-----------------------------------------------------------------------------+
| Warning | 1916 | Got overflow when converting '18446744073709551615' to INT. Value truncated |
+---------+------+-----------------------------------------------------------------------------+

+---------------------+
| a+0                 |
+---------------------+
| 9223372036854775807 |
+---------------------+

Generated at Thu Feb 08 07:33:53 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.