I found that data types like int and decimal can still exceed the defined length after being defined

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: int、decimal这种数据类型我发现定义后仍然可以超过定义的长度

| username: 学无止境

For example, numbers like int(3) and 124576894 can still be stored.
decimal(2.2) can still store numbers like 1.2323258.

  1. Does this mean that there is no need to define a specific numerical range for int and decimal, or is it unnecessary? Even if defined, there are no restrictions.
  2. Is there no difference between defining and not defining a numerical range?
| username: WalterWj | Original post link

Is the SQL mode turned off strict mode? Although the write was successful, it should have been truncated.

| username: 学无止境 | Original post link

Tomorrow, I can check what mode it is. From what I see, it just stores what I want to insert without truncation.

| username: zhanggame1 | Original post link

There is no difference between int(3) and int(100), both are stored in 4 bytes.

| username: Kongdom | Original post link

You can take a look here, it seems to just control the display.

| username: zhaokede | Original post link

Setting the bit length for an int has no effect; the largest number is still 2 to the power of 32.

| username: redgame | Original post link

Only affects display, does not affect storage.

| username: TiDBer_777987 | Original post link

I see, I’ll give it a try.

| username: DBAER | Original post link

int has a fixed size, while int(3) specifies the number of digits for formatted display. For example, with int(4), if your data is 10, it will be displayed as 10.00, with the formatted output using placeholders accordingly.

| username: TiDBer_LM | Original post link

(数值类型 | PingCAP 文档中心)

INTEGER Type

The INTEGER type, alias INT. The range for signed numbers is [-2147483648, 2147483647]. The range for unsigned numbers is [0, 4294967295].

INT[(M)] [UNSIGNED] [ZEROFILL]

Field Description:

Syntax Element Description
M Type display width, optional
| username: 小于同学 | Original post link

Caused by the configuration of SQL mode

| username: chris-zhang | Original post link

It’s a question about the configuration of SQL mode, right?