[MDEV-10307] CAST(11068046444225730969 AS SIGNED) does not return a warning Created: 2016-06-29  Updated: 2019-04-30  Resolved: 2019-04-30

Status: Closed
Project: MariaDB Server
Component/s: OTHER
Affects Version/s: 10.0, 10.1, 10.2, 10.3, 10.4
Fix Version/s: 10.3.15, 10.4.5

Type: Bug Priority: Minor
Reporter: Alexander Barkov Assignee: Alexander Barkov
Resolution: Fixed Votes: 0
Labels: None


 Description   

This script:

SELECT CAST(-7378697629483820647 AS UNSIGNED);

returns

+----------------------------------------+
| CAST(-7378697629483820647 AS UNSIGNED) |
+----------------------------------------+
|                   11068046444225730969 |
+----------------------------------------+
1 row in set, 1 warning (0.00 sec)

with a warning:

+-------+------+-------------------------------------------------------------------------+
| Level | Code | Message                                                                 |
+-------+------+-------------------------------------------------------------------------+
| Note  | 1105 | Cast to unsigned converted negative integer to it's positive complement |
+-------+------+-------------------------------------------------------------------------+

If I now do the other way around:

SELECT CAST(11068046444225730969 AS SIGNED);

it returns this result:

+--------------------------------------+
| CAST(11068046444225730969 AS SIGNED) |
+--------------------------------------+
|                 -7378697629483820647 |
+--------------------------------------+
1 row in set (0.00 sec)

but no warning is issued.

Expect to get a warning Cast to signed converted positive integer to it's negative complement



 Comments   
Comment by Alexander Barkov [ 2016-06-29 ]

If I now do the same conversion using COLUMN_CREATE/COLUMN_GET:

SELECT COLUMN_GET(COLUMN_CREATE(0, 11068046444225730969), 0 AS SIGNED);
SHOW WARNINGS;

it correctly returns the result and the warning:

+-----------------------------------------------------------------+
| COLUMN_GET(COLUMN_CREATE(0, 11068046444225730969), 0 AS SIGNED) |
+-----------------------------------------------------------------+
|                                            -7378697629483820647 |
+-----------------------------------------------------------------+
1 row in set, 1 warning (0.00 sec)

+-------+------+------------------------------------------------------------------------------------+
| Level | Code | Message                                                                            |
+-------+------+------------------------------------------------------------------------------------+
| Note  | 1105 | Cast to signed converted positive out-of-range integer to it's negative complement |
+-------+------+------------------------------------------------------------------------------------+

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