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