mysql 中的“NUMERIC maxsize 256”是什么意思?
What does `NUMERIC maxsize 256` mean in mysql?
这是一个数据字段定义:
Field Name
Field Description
Field Type (format)
Max Size
May be NULL
Key
tag
The unique identifier (name) for a tag in a specific taxonomy release.
ALPHANUMERIC
256
No
*
version
For a standard tag, an identifier for the taxonomy; otherwise the accession number where the tag was defined.
ALPHANUMERIC
20
No
*
ddate
The end date for the data value, rounded to the nearest month end.
DATE (yyyymmdd)
8
No
*
qtrs
The count of the number of quarters represented by the data value, rounded to the nearest whole number. “0” indicates it is a point-in-time value.
NUMERIC
8
No
*
uom
The unit of measure for the value.
ALPHANUMERIC
20
No
*
coreg
If specified, indicates a specific co-registrant, the parent company, or other entity (e.g., guarantor). NULL indicates the consolidated entity.
NUMERIC
256
Yes
*
value
The value. This is not scaled, it is as found in the Interactive Data file, but is limited to four digits to the right of the decimal point.
NUMERIC(28,4)
16
Yes
footnote
The text of any superscripted footnotes on the value, as shown on the statement page, truncated to 512 characters, or if there is no footnote, then this field will be blank.
ALPHANUMERIC
512
Yes
字段定义是SEC U.S. Securities and Exchange Commission
的官方material:
对于coreg
,它的字段类型是数字,最大大小256,如何写创建语句?
CREATE TABLE `num` (
`id` INT NOT NULL AUTO_INCREMENT,
`tag` VARCHAR(256) NOT NULL,
`version` VARCHAR(20) NOT NULL,
`ddate` DATE NOT NULL,
`qtrs` DECIMAL(8) NOT NULL,
`uom` VARCHAR(20) NOT NULL,
`coreg` ?,
`value` DECIMAL(28,4),
`footnote` VARCHAR(512),
PRIMARY KEY (id)
);
要写如下字段定义?
`coreg` NUMERIC(256)
在 MySQL 中,decimal
(numeric
) 类型的最大位数是 65。
因此,从技术上讲,您不能将列定义为 NUMERIC(256)
。
11.1.3 Fixed-Point Types (Exact Value) - DECIMAL, NUMERIC
The maximum number of digits for DECIMAL is 65
将“母公司或其他实体(例如,担保人)”定义为数字,即使是非常长的数字,对我来说也没有任何意义。
可能有错字,实际上它应该读作“ALPHANUMERIC”,即文本值。
如果此值永远不会被解释为数字并且永远不会尝试使用此数字进行某些计算(正如字段描述所暗示的那样),则应将其存储为文本 (varchar(256)
);也许有一些额外的检查,你可以只存储数字 0-9 而不是任何符号。
这可能意味着它只是一长串数字。您通常会将其存储为 NUMERIC
,但 256 位的大小超出了 MySQL 对数字类型的限制。但是,您可以将其存储为 VARCHAR(256)
并在其上添加 CHECK
约束。
注意:CHECK
约束仅在 MySQL 8.0(8.0.3?)和更新版本中强制执行。
例如:
create table t (
coreg varchar(256) check (coreg regexp '^[0-9]+$')
);
insert into t (coreg) values ('123');
insert into t (coreg) values ('x456'); -- fails
insert into t (coreg) values ('7y89'); -- fails
insert into t (coreg) values ('012z'); -- fails
insert into t (coreg) values ('345 '); -- fails
参见 db<>fiddle 中的 运行 示例。
这是一个数据字段定义:
Field Name | Field Description | Field Type (format) | Max Size | May be NULL | Key |
---|---|---|---|---|---|
tag | The unique identifier (name) for a tag in a specific taxonomy release. | ALPHANUMERIC | 256 | No | * |
version | For a standard tag, an identifier for the taxonomy; otherwise the accession number where the tag was defined. | ALPHANUMERIC | 20 | No | * |
ddate | The end date for the data value, rounded to the nearest month end. | DATE (yyyymmdd) | 8 | No | * |
qtrs | The count of the number of quarters represented by the data value, rounded to the nearest whole number. “0” indicates it is a point-in-time value. | NUMERIC | 8 | No | * |
uom | The unit of measure for the value. | ALPHANUMERIC | 20 | No | * |
coreg | If specified, indicates a specific co-registrant, the parent company, or other entity (e.g., guarantor). NULL indicates the consolidated entity. | NUMERIC | 256 | Yes | * |
value | The value. This is not scaled, it is as found in the Interactive Data file, but is limited to four digits to the right of the decimal point. | NUMERIC(28,4) | 16 | Yes | |
footnote | The text of any superscripted footnotes on the value, as shown on the statement page, truncated to 512 characters, or if there is no footnote, then this field will be blank. | ALPHANUMERIC | 512 | Yes |
字段定义是SEC U.S. Securities and Exchange Commission
的官方material:
对于coreg
,它的字段类型是数字,最大大小256,如何写创建语句?
CREATE TABLE `num` (
`id` INT NOT NULL AUTO_INCREMENT,
`tag` VARCHAR(256) NOT NULL,
`version` VARCHAR(20) NOT NULL,
`ddate` DATE NOT NULL,
`qtrs` DECIMAL(8) NOT NULL,
`uom` VARCHAR(20) NOT NULL,
`coreg` ?,
`value` DECIMAL(28,4),
`footnote` VARCHAR(512),
PRIMARY KEY (id)
);
要写如下字段定义?
`coreg` NUMERIC(256)
在 MySQL 中,decimal
(numeric
) 类型的最大位数是 65。
因此,从技术上讲,您不能将列定义为 NUMERIC(256)
。
11.1.3 Fixed-Point Types (Exact Value) - DECIMAL, NUMERIC
The maximum number of digits for DECIMAL is 65
将“母公司或其他实体(例如,担保人)”定义为数字,即使是非常长的数字,对我来说也没有任何意义。
可能有错字,实际上它应该读作“ALPHANUMERIC”,即文本值。
如果此值永远不会被解释为数字并且永远不会尝试使用此数字进行某些计算(正如字段描述所暗示的那样),则应将其存储为文本 (varchar(256)
);也许有一些额外的检查,你可以只存储数字 0-9 而不是任何符号。
这可能意味着它只是一长串数字。您通常会将其存储为 NUMERIC
,但 256 位的大小超出了 MySQL 对数字类型的限制。但是,您可以将其存储为 VARCHAR(256)
并在其上添加 CHECK
约束。
注意:CHECK
约束仅在 MySQL 8.0(8.0.3?)和更新版本中强制执行。
例如:
create table t (
coreg varchar(256) check (coreg regexp '^[0-9]+$')
);
insert into t (coreg) values ('123');
insert into t (coreg) values ('x456'); -- fails
insert into t (coreg) values ('7y89'); -- fails
insert into t (coreg) values ('012z'); -- fails
insert into t (coreg) values ('345 '); -- fails
参见 db<>fiddle 中的 运行 示例。