博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CAST function should support INT synonym for SIGNED. i.e. CAST(y AS INT)
阅读量:6516 次
发布时间:2019-06-24

本文共 4336 字,大约阅读时间需要 14 分钟。

 

 

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: 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)
  • View
[19 Jun 2014 15:55] Morgan Tocker
Description:Reported via twitter: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 1mysql [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 ---------------------------------          ::=                
[ CHARACTER SET
] |
|
|
|
|
::= CHARACTER [
] | CHAR [
] | CHARACTER VARYING
can be used in
...--------------------------------------------------
::= CAST
AS
::=
|
... and also in
-----------------------------------
::= CREATE [ { GLOBAL | LOCAL } TEMPORARY ] TABLE
::=
[ {
}... ]
|
::=
::=
{
|
}MySQL has its own way of dealing with data types when used in a
. 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
.
[30 Jun 2014 11:12] Umesh Umesh
Hello Morgan,Thank you for the feature request!// Oracle Database 11gSQL> SELECT CAST ('5' AS INT) from dual;CAST('5'ASINT)--------------             5SQL> SELECT * FROM V$VERSION;BANNER--------------------------------------------------------------------------------Oracle Database 11g Express Edition Release 11.2.0.2.0 - ProductionPL/SQL Release 11.2.0.2.0 - ProductionCORE    11.2.0.2.0      ProductionTNS for 32-bit Windows: Version 11.2.0.2.0 - ProductionNLSRTL Version 11.2.0.2.0 - ProductionSQL>// MySQL 5.7mysql> 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 1mysql>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.

转载于:https://www.cnblogs.com/kungfupanda/p/5931791.html

你可能感兴趣的文章
WTL介绍
查看>>
应用程序框架实战三十四:数据传输对象(DTO)介绍及各类型实体比较(转)
查看>>
放量滞涨,抛出信号
查看>>
windows 下配置 Nginx 常见问题(转)
查看>>
BeanFactory not initialized or already closed - call 'refresh' before accessing beans解决办法
查看>>
dSYM 文件分析工具
查看>>
R语言合并data.frame
查看>>
linux主机下的Vmware Workstation配置NAT设置 端口映射-Ubuntu为例
查看>>
unity physics joint
查看>>
TD的访问地址
查看>>
JAVA常见面试题之Forward和Redirect的区别
查看>>
tmpFile.renameTo(classFile) failed 错误
查看>>
【甘道夫】Apache Hadoop 2.5.0-cdh5.2.0 HDFS Quotas 配额控制
查看>>
一张图看懂normal,static,sealed,abstract 的 区别
查看>>
Task的使用
查看>>
grep和正则表达式
查看>>
s:iterator巧妙控制跳出循环
查看>>
移动互联网思维
查看>>
redis-手写redis切片和非切片连接池并注入springboot中
查看>>
Kosaraju算法详解
查看>>