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. JS面向对象(3) -- Object类,静态属性,闭包,私有属性, call和apply的使用,继承的三种实现方法

    相关链接: JS面向对象(1) -- 简介,入门,系统常用类,自定义类,constructor,typeof,instanceof,对象在内存中的表现形式 JS面向对象(2) -- this的使用,对 ...

  2. JS函数 -- 功能,语法,返回值,匿名函数,自调用匿名函数,全局变量与局部变量,arguments的使用

    “JavaScript设计得最出色的就是它的函数的实现.” -- <JavaScript语言精粹> 函数包含一组语句,它们是JS的基础模块单元,用于指定对象的行为.一般来说,所谓编程,就是 ...

  3. 使用未付费的账号真机调试 iOS 程序,过几天后程序一打开就会闪退

    使用未付费的苹果开发者账号真机调试 iOS 程序,过几天后程序一打开就会闪退.   解决办法: 删除 Provisioning Profile,重新配置一次. 终极解决办法:花钱购买苹果开发者账号. ...

  4. OleDB Destination 用法

    第一部分:简介 OleDB Destination component 是将数据流load 到destination,共有5种Data Access Mode,一般的Destination compo ...

  5. Minor【 PHP框架】5.事件

    框架Github地址:github.com/Orlion/Minor (如果觉得还不错给个star哦(^-^)V) 框架作者: Orlion 知乎:https://www.zhihu.com/peop ...

  6. 创建第一个 local network(II)- 每天5分钟玩转 OpenStack(81)

    上一节通过 Web GUI 创建了 “first_local_net”,本节我们需要搞清楚底层网络结构有了哪些变化? 点击 “first_local_net” 链接,显示 network 的 subn ...

  7. IOS开发之自动布局显示网络请求内容

    在上一篇博客中详细的介绍了IOS开发中的相对布局和绝对布局,随着手机屏幕尺寸的改变,在App开发中为了适应不同尺寸的手机屏幕,用自动布局来完成我们想要实现的功能和效果显得尤为重要.本人更喜欢使用相对布 ...

  8. setTimeout与取号机之间的关系

    说到setTimeout写过javascript的伙伴们一定不会陌生,去银行办过存取款业务的伙伴一定对取号机不会陌生.今天群里有个好伙伴在问setTimeout的问题,大伙你一言我一语,讲了很多,可是 ...

  9. ASP.NET 5 使用 TestServer 进行单元测试

    之前如果对 ASP.NET WebAPI 进行单元测试(HttpClient 发起请求,并且可调试 WebAPI),一般采用 Owin 的方式,具体参考:<开发笔记:用 Owin Host 实现 ...

  10. 深入理解 OWIN 中的 Host 和 Server

    The Open Web Interface for .NET (OWIN),注意单词为大写,之前好像都写成了 Owin,但用于项目的时候,可以写成:Microsoft.Owin.*. OWIN 体系 ...