随笔 - 116  文章 - 5  评论 - 1  阅读 - 14万

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 这种方式是不赞成这样写的,它很有可能在将来的某个版本上被删除。

 

posted on   JennyYu  阅读(310)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示