GreatDB与mysql8 的 int 类型
Greatdb Cluster 5.0 的语法可以参考 mysql 8
int 类型
经常有开发建表的时候会使用int(4) 来指定列类型,那么这个4代表的是什么,它并不表示存储的字节,因为int类型用4个字节存储是数据库定的。
这个4指的是数字显示的宽度,插入数字超过4位,正常显示,不足4位时,可以指定以0填充,不指定以什么填充,(4)没有意义,数字就正常显示。
下面以一个实验来说明。
GreatDB Cluster[test]> show warnings;
+---------+------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Level | Code | Message |
+---------+------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Warning | 1681 | The ZEROFILL attribute is deprecated and will be removed in a future release. Use the LPAD function to zero-pad numbers, or store the formatted numbers in a CHAR column. |
| Warning | 1681 | Integer display width is deprecated and will be removed in a future release. |
| Warning | 1681 | Integer display width is deprecated and will be removed in a future release. |
+---------+------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
3 rows in set (0.00 sec)GreatDB Cluster[test]> insert into t values(1,1);
Query OK, 1 row affected (0.02 sec)GreatDB Cluster[test]> insert into t values(10000,10000);
Query OK, 1 row affected (0.01 sec)GreatDB Cluster[test]> select *from t;
+-------+-------+
| id | col1 |
+-------+-------+
| 0001 | 1 |
| 10000 | 10000 |
+-------+-------+
2 rows in set (0.00 sec)
根据警告,我们发现int(4) zerofill 这种方式是不赞成这样写的,它很有可能在将来的某个版本上被删除。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?