Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.
Original topic: int、decimal这种数据类型我发现定义后仍然可以超过定义的长度
For example, numbers like int(3) and 124576894 can still be stored.
decimal(2.2) can still store numbers like 1.2323258.
- 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.
- Is there no difference between defining and not defining a numerical range?
Is the SQL mode turned off strict mode? Although the write was successful, it should have been truncated.
Tomorrow, I can check what mode it is. From what I see, it just stores what I want to insert without truncation.
There is no difference between int(3) and int(100), both are stored in 4 bytes.
You can take a look here, it seems to just control the display.
Setting the bit length for an int has no effect; the largest number is still 2 to the power of 32.
Only affects display, does not affect storage.
I see, I’ll give it a try.
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.
(数值类型 | 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 |
Caused by the configuration of SQL mode
It’s a question about the configuration of SQL mode, right?