Bug #73054 CAST function should support INT synonym for SIGNED. i.e. CAST(y AS INT)
Submitted: 19 Jun 2014 15:55 Modified: 30 Jun 2014 11:12
Reporter: Morgan Tocker Email Updates:
Status: Verified Impact on me: None 
Category: MySQL Server: DML Severity: S4 (Feature request)
Version:   OS: Any
Assigned to:      
Triage: Needs Triage: D5 (Feature request)
[19 Jun 2014 15:55] Morgan Tocker
Description:
Reported via twitter:
https://twitter.com/lukaseder/status/479288364106280960 Other databases will support CAST(y AS INT), but MySQL requires CAST(y AS SIGNED). I tried reading the SQL-92 standard (not the easiest text to follow), and it doesn't seem to indicate it must be SIGNED. Is it possible to support INT as an alias for interoperability? How to repeat:
mysql [localhost] {msandbox} (test) > select version();
+-----------+
| version() |
+-----------+
| 5.7.4-m14 |
+-----------+
1 row in set (0.00 sec) mysql [localhost] {msandbox} (test) > SELECT CAST('5' as INT);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INT)' at line 1
mysql [localhost] {msandbox} (test) > SELECT CAST('5' as SIGNED);
+---------------------+
| CAST('5' as SIGNED) |
+---------------------+
| 5 |
+---------------------+
1 row in set (0.00 sec) Suggested fix:
mysql [localhost] {msandbox} (test) > SELECT CAST('5' as INT);
+---------------------+
| CAST('5' as INT) |
+---------------------+
| 5 |
+---------------------+
1 row in set (0.01 sec)
[19 Jun 2014 16:14] Lukas Eder
Thanks for reporting this, Morgan.

Some additional notes on my motivation (in the original Tweet). All other SQL dialects support the same type notation for CAST expressions as for column specifications in DDL. Concretely (citing parts from SQL-92):

General definition of <data type>
--------------------------------- <data type> ::=
<character string type> [ CHARACTER SET <character set specification> ]
| <national character string type>
| <bit string type>
| <numeric type>
| <datetime type>
| <interval type> <character string type> ::=
CHARACTER [ <left paren> <length> <right paren> ]
| CHAR [ <left paren> <length> <right paren> ]
| CHARACTER VARYING <left paren> <length> <right paren> <data type> can be used in <cast specification>...
-------------------------------------------------- <cast specification> ::=
CAST <left paren> <cast operand> AS <cast target> <right paren> <cast target> ::=
<domain name>
| <data type> ... and also in <table definitions>
----------------------------------- <table definition> ::=
CREATE [ { GLOBAL | LOCAL } TEMPORARY ] TABLE <table name>
<table element list> <table element list> ::=
<left paren> <table element> [ { <comma> <table element> }... ] <right paren> <table element> ::=
<column definition>
| <table constraint definition> <column definition> ::=
<column name> { <data type> | <domain name> } MySQL has its own way of dealing with data types when used in a <cast specification>. Apart from possibly historic reasons, it is unclear why there are two sets of data types that cannot be used interchangeably. Obviously, this is not limited to INT types, but to all supported data types, which should be supported as <cast targets>.
[30 Jun 2014 11:12] Umesh Umesh
Hello Morgan,

Thank you for the feature request!

// Oracle Database 11g

SQL> SELECT CAST ('5' AS INT) from dual;

CAST('5'ASINT)
--------------
5 SQL> SELECT * FROM V$VERSION; BANNER
-------------------------------------------------------------------------------- Oracle Database 11g Express Edition Release 11.2.0.2.0 - Production
PL/SQL Release 11.2.0.2.0 - Production
CORE 11.2.0.2.0 Production
TNS for 32-bit Windows: Version 11.2.0.2.0 - Production
NLSRTL Version 11.2.0.2.0 - Production SQL> // MySQL 5.7 mysql> SELECT CAST('5' as INT);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INT)' at line 1
mysql>
mysql> SELECT CAST('5' as SIGNED);
+---------------------+
| CAST('5' as SIGNED) |
+---------------------+
| 5 |
+---------------------+
1 row in set (0.00 sec) mysql> Thanks,
Umesh
[7 Oct 2015 20:08] Simon Mudd
I think we miss some other things here.
MySQL has several sizes of int apart from them being signed or unsigned. So the CAST() function should really be able to convert to these specific types as the resultant value may later be used in a comparison. So probably we should have CAST( XXXX AS [unsigned] (big|medium|tiny|)int ) to be clearer here and to catch out of value cast conversions which probably at least in strict mode should generate an error. I also miss the possibility of CASTing into a timestamp(X) value as these days we may find that useful. The reason for the CAST() as far as I can see is to force the resultant type to be something very specific so that anywhere the value is later used there's no doubt what type and size it has.

CAST function should support INT synonym for SIGNED. i.e. CAST(y AS INT)的更多相关文章

  1. [ActionScript 3.0] 用TextField的方法getCharIndexAtPoint(x:Number, y:Number):int实现文字在固定范围内显示

    有时候我们遇到一行文字过多时必须固定文字的显示范围,但由于中英文所占字节数不一样,所以不能很好的用截取字符的方式去统一显示范围的大小,用TextField的getCharIndexAtPoint(x: ...

  2. flultter listview异常type '(BuildContext, int) => dynamic' is not a subtype of type '(BuildContext, int) => Widget'

    type '(BuildContext, int) => dynamic' is not a subtype of type '(BuildContext, int) => Widget' ...

  3. SQL技术内幕-7 varchar类型的数字和 int 类型的数字的比较+cast的适用

    DECLARE @x VARCHAR(10); DECLARE @y INT; DECLARE @z VARCHAR(10); SET @x = '1000'; SET @y = '2000'; SE ...

  4. MySQL数据类型 int(M) 表示什么意思?详解mysql int类型的长度值问题

    MySQL 数据类型中的 integer types 有点奇怪.你可能会见到诸如:int(3).int(4).int(8) 之类的 int 数据类型.刚接触 MySQL 的时候,我还以为 int(3) ...

  5. Java中返回值定义为int类型的 方法return 1返回的是int还是Integer&&finally中return问题

    在Java中返回值定义为int类型的 方法return 1:中返回的是Integer值,在返回的时候基本类型值1被封装为Integer类型. 定义一个Test类,在异常处理try中和finally中分 ...

  6. path('<int:question_id>/vote/', views.vote, name='vote')中的<int:question_id>的含义

    path('<int:question_id>/vote/', views.vote, name='vote')<int:question_id>用于匹配URL的值,并将扑捉到 ...

  7. 为什么声明了int型的变量并且直接初始化后,int型变量的地址一直在变化?

    /************************************************************************* > File Name: ptr_varia ...

  8. java中int和Integer的区别?为什么有了int还要有设计Integer?

    参考https://blog.csdn.net/chenliguan/article/details/53888018 https://blog.csdn.net/myme95/article/det ...

  9. C++ Core Guidelines

    C++ Core Guidelines September 9, 2015 Editors: Bjarne Stroustrup Herb Sutter This document is a very ...

随机推荐

  1. 实现Div拖拽

    直观的理解div拖拽:当鼠标对着可拖拽部分按住后并拖动,div会跟着鼠标一起运动,并且其运动空间限制在浏览器内部,当放开鼠标时,则div停止运动. 实现div拖拽需要三个重要的事件: (1)onmou ...

  2. HTML5中类jQuery选择器querySelector的使用

    简介 HTML5向Web API新引入了document.querySelector以及document.querySelectorAll两个方法用来更方便地从DOM选取元素,功能类似于jQuery的 ...

  3. 用FlexGrid做开发,轻松处理百万级表格数据

    表格数据处理是我们项目开发中经常会遇到的设计需求之一,所需处理的数据量也较大,通常是万级.甚至百万级.此时,完全依赖平台自带的表格工具,往往无法加载如此大的数据量,或者加载得很慢影响程序执行. 那么, ...

  4. C语言 · 矩阵乘法

    问题描述 输入两个矩阵,分别是m*s,s*n大小.输出两个矩阵相乘的结果. 输入格式 第一行,空格隔开的三个正整数m,s,n(均不超过200). 接下来m行,每行s个空格隔开的整数,表示矩阵A(i,j ...

  5. C语言 · 查找整数

    问题描述 给出一个包含n个整数的数列,问整数a在数列中的第一次出现是第几个. 输入格式 第一行包含一个整数n. 第二行包含n个非负整数,为给定的数列,数列中的每个数都不大于10000. 第三行包含一个 ...

  6. 【NodeJS 学习笔记04】新闻发布系统

    前言 昨天,我们跟着这位大哥的博客(https://github.com/nswbmw/N-blog/wiki/_pages)进行了nodeJS初步的学习,最后也能将数据插入数据库了 但是一味的跟着别 ...

  7. IL指令汇总

    名称 说明   名称 说明 Add 将两个值相加并将结果推送到计算堆栈上.   Ldelem.I1 将位于指定数组索引处的 int8 类型的元素作为 int32 加载到计算堆栈的顶部. Add.Ovf ...

  8. GitFlow

    git工作流 始终保持有master分支(只要有目录,git就自动创建)和develop分支(手动创建) 一.主分支Master二.开发分支Develop三.临时性分支(最后发布要删除的)* 功能(f ...

  9. 【SQL】SQL Server登录常见问题

    很多人SQL装的很不规范,导致各种问题或者说时间长了,密码给忘记了,怎么办呢?重装? 逆天就拿几个比较常见的来说事吧,首先是各种设置的问题:(我家里用的是简易版,你们开发最好用企业版)         ...

  10. 【Win10应用开发】通过拖放来打开文件

    除了可以使用XXXFilePicker来浏览文件外,其实在UWP APP中,也可以向传统Windows窗口一样,通过拖放的方式来打开文件. 处理过程和WPF的原理差不多,毕竟都是一脉相承,于是,在学习 ...