MySQL与openGauss的数据类型对比
需要注意的是,下面列出来的MySQL数据类型指的是information_schema.COLUMNS中的data_type而非column_type。比如对于 int unsigned的column_type,其data_type实际为 int。对于float(5,2)的column_type,其data_type实际为float。
char(1)类型能够正常插入汉字跟数据库模式有关。当数据库是B模式(加载了dolphin插件),char(1)可成功插入1个汉字;当数据库是A模式时,插入1个汉字会失败。 openGauss B库数据类型参考:https://docs-opengauss.osinfra.cn/zh/docs/latest/docs/ExtensionReference/dolphin-%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B.html
| MySQL | openGauss | 备注 |
|---|---|---|
| int | integer | 若column_type包含unsigned或者zerofill属性,则类型映射转化为openGauss侧的uint4 |
| tinyint | tinyint | 若column_type包含unsigned或者zerofill属性,则类型映射转化为openGauss侧的uint1 |
| smallint | smallint | 若column_type包含unsigned或者zerofill属性,则类型映射转化为openGauss侧的uint2 |
| mediumint | integer | openGauss侧mediumint与integer等价,存储空间为4字节,mysql侧的mediumint存储空间为3字节,因此openGauss对应的数值范围更大;若column_type包含unsigned或者zerofill属性,则类型映射转化为openGauss侧的uint4 |
| bigint | bigint | 若column_type包含unsigned或者zerofill属性,则类型映射转化为openGauss侧的uint8 |
| char | character | 支持迁移最大存储长度(character_maximum_length),默认长度为1 |
| varchar | character varying | 支持迁移最大存储长度(character_maximum_length) |
| date | date | |
| time | time without time zone | MySQL的time类型对应openGauss的time类型,对应的data_type类型为time without time zone |
| datetime | timestamp without time zone | MySQL的datetime类型对应openGauss的datetime类型,对应的data_type类型为timestamp without time zone |
| timestamp | timestamp with time zone | MySQL的timestamp类型对应openGauss的timestamp类型,对应的data_type类型为timestamp with time zone |
| year | year | 支持设置宽度,year(w),w表示宽度,year(4)输出'YYYY',year(2)输出'YY' |
| text | text | |
| tinytext | text | openGauss侧tinytext、mediumtext和longtext均是text的别名,与text等价 |
| mediumtext | text | openGauss侧tinytext、mediumtext和longtext均是text的别名,与text等价 |
| longtext | text | openGauss侧tinytext、mediumtext和longtext均是text的别名,与text等价 |
| blob | blob | |
| tinyblob | tinyblob | |
| mediumblob | mediumblob | |
| longblob | longblob | |
| binary | binary | |
| varbinary | varbinary | |
| decimal | numeric | 当mysql侧column_type为decimal, dec, numeric和fixed类型时,data_type均对应decimal类型;这些类型均有type, type(p)和type(p,s)三种格式,若未指定精度(p,s),形如type,则为默认精度type(10,0);若未指定s,形如type(p),则默认s=0,即type(p,0);支持迁移精度numeric_precision和numeric_scale,迁移后的类型为numeric(p,s)。 |
| double | numeric | 当mysql侧column_type为double,double precision和real类型时,data_type均对应double类型;这些类型均有type和type(p,s)两种格式;若指定精度(p和s),当s!=0时,类型映射转化为numeric(p,s),当s=0时,类型转化为float(p);若未指定精度,则类型映射转换为number,即无默认(10,0)精度的numeric类型。 |
| float | real | 当mysql侧column_type为float类型时,data_type对应float类型;float类型有type, type(p)和type(p,s)三种格式,若指定精度(p和s),当s!=0时,类型映射转化为numeric(p,s),当s=0时,类型转化为float(p);若指定p,类型映射转换为float(p),当p位于[1, 24]时,对应data_type为real,当p位于[25, 53]时,对应data_type为double precision;若未指定p,类型映射为float,对应data_type为real。 |
| bit | bit | 支持迁移最大存储长度(character_maximum_length),默认长度为1 |
| enum | enum | |
| set | set | |
| json | json | |
| geometry | point | 若openGauss侧安装有postgis,将迁移成geometry类型 |
| point | point | 若openGauss侧安装有postgis,将迁移成geometry类型 |
| linestring | path | 若openGauss侧安装有postgis,将迁移成geometry类型 |
| polygon | polygon | 若openGauss侧安装有postgis,将迁移成geometry类型 |
| multipoint | bytea | 若openGauss侧安装有postgis,将迁移成geometry类型 |
| geometrycollection | bytea | 若openGauss侧安装有postgis,将迁移成geometry类型 |
| multilinestring | bytea | 若openGauss侧安装有postgis,将迁移成geometry类型 |
| multipolygon | bytea | 若openGauss侧安装有postgis,将迁移成geometry类型 |
意见反馈