When you change the data type of a column in the MySQL mode of OceanBase Database, you must first consider the table-level column type change rules, especially in scenarios where some data types are forbidden, and then consider the change rules concerning the source data type and target data type.
Table-level column type change rules
Prohibitory rules
FOREIGN KEYconstraintsThe data type of a foreign key column cannot be changed by using online or offline DDL operations except in the following special cases. Note that only the display precision is changed and the storage structure is not changed.
If the data type of the column is
FLOAT(m,n), you can change the precision. However, conversion betweenSIGNEDandUNSIGNEDis not supported.If the data type of the column is
DOUBLE(m,n), you can change the precision. However, conversion betweenSIGNEDandUNSIGNEDis not supported.If the data type of the column is
VARCHAR(m), you can only increase the precision. You cannot decrease the precision or change the data type toCHAR.
CHECKconstraintsYou cannot change the data type of a column with a
CHECKconstraint, except for a column of theINTEGERtype, by using online or offline DDL operations.Trigger constraints
You cannot change the data type of a column with a non-
DISABLEtrigger constraint by using offline DDL operations. For a table with only aDISABLEtrigger, DDL operations are not affected, and the new table must contain thisDISABLEtrigger.
Change rules
You can increase the length of a column without changing its data type, for example, change a
VARCHAR(8)column to aVARCHAR(11)column, by using an online DDL operation without rewriting data.- If you perform an online DDL operation to change the length of a column with a dependent object such as an index table, for example, increase the length of a
VARCHARcolumn, you must also change the schema of the dependent object. In other words, the schema of the dependent object must still be changed even though data is expected not to change. - You can perform an online DDL operation to increase the length of an
INTEGERorDECIMALINTcolumn when it is an indexed column or a primary key column.
- If you perform an online DDL operation to change the length of a column with a dependent object such as an index table, for example, increase the length of a
OceanBase Database supports online DDL operations for increasing the length of
LOBcolumns in the following scenarios:- Modify a
LOBcolumn as a normal column. - Modify a
LOBcolumn as a stored generated column or a virtual generated column. - Modify a
LOBcolumn as a column on which a stored generated column or a virtual generated column depends. - Add a
NOT NULLorCHECKconstraint to aLOBcolumn. - Modify the original
NOT NULLconstraint for aLOBcolumn.
- Modify a
When column type change is allowed, to convert between
SIGNEDandUNSIGNEDvalues of a numeric data type, perform an offline DDL operation. When column type change is allowed, to change the character set and collation, perform an offline DDL operation.If a column is referenced by a generated column, you can still change its data type.
Column-level conversion rules
In OceanBase Database, all column data types are classified into three categories: numeric data types, character data types, and date and time data types. The conversion rules are similar for the three categories. The change rules are also similar within each category. However, some special cases exist.
The following tables describe the conversion between categories and within each category.
Conversion between numeric data types
Numeric data types include the following ones:
Integer types:
TINYINT,SMALLINT,MEDIUMINT,INT, andBIGINTFloating-point types:
FLOATandDOUBLEFixed-point type:
NUMBERBinary type:
BIT
The following table describes the conversion between numeric data types.
| Data type | To TINYINT, SMALLINT, MEDIUMINT, INT, and BIGINT | To FLOAT and DOUBLE | To NUMBER | To BIT |
|---|---|---|---|---|
| Integer types | Supported | Supported | Supported | Supported |
| Floating-point types | Supported | Supported | Supported | Supported |
| Fixed-point type | Supported | Supported | Supported | Supported |
| Binary type | Supported | Supported | Supported | Supported |
Conversion between character data types
Character data types include the following ones:
CHARandVARCHARBINARYandVARBINARYTEXTtypes:TINYTEXT,MEDIUMTEXT,TEXT, andLONGTEXTBLOBtypes:TINYBLOB,MEDIUMBLOB,BLOB, andLONGBLOBENUMandSET
The following table describes the conversion between character data types.
| Data type | To CHAR | To BINARY | To VARCHAR and VARBINARY | To TEXT and BLOB | To ENUM and SET |
|---|---|---|---|---|---|
CHAR |
Supported | Supported | Supported | Supported | Supported |
BINARY |
Supported | Supported | Supported | Supported | Supported |
VARCHAR and VARBINARY |
Supported | Supported | Supported | Supported | Supported |
TEXT and BLOB types |
Supported | Supported | Supported | Supported | Supported |
ENUM and SET |
Supported | Supported | Supported | Supported | Supported |
Conversion between date and time data types
Date and time data types include the following ones:
DATETIMESTAMPDATETIMETIMEYEAR
The following table describes the conversion between date and time data types.
| Data type | To DATE | To TIMESTAMP | DATETIME | TIME | YEAR |
|---|---|---|---|---|---|
DATE |
Supported | Supported | Supported | Supported | Supported |
TIMESTAMP |
Supported | Supported | Supported | Supported | Supported |
DATETIME |
Supported | Supported | Supported | Supported | Supported |
TIME |
Supported | Supported | Supported | Supported | Supported |
YEAR |
Supported | Supported | Supported | Supported | Supported |
Conversion between numeric data types and character data types
The following table describes the conversion between numeric data types and character data types.
| Data type | To integer, floating-point, and fixed-point types | To BIT | To CHAR, BINARY, VARCHAR, VARBINARY, TEXT types, and BLOB types | To ENUM and SET |
|---|---|---|---|---|
| Integer, floating-point, and fixed-point types | See rules for conversion within the category | See rules for conversion within the category | Supported | Supported |
BIT |
See rules for conversion within the category | See rules for conversion within the category | Supported | Supported |
CHAR, BINARY, VARCHAR, VARBINARY, TEXT types, and BLOB types |
Supported | Supported | See rules for conversion within the category | Supported |
ENUM and SET |
Supported | Supported | See rules for conversion within the category | See rules for conversion within the category |
Conversion between numeric data types and date and time data types
The following table describes the conversion between numeric data types and date and time data types.
| Data type | To integer, floating-point, fixed-point, and BIT types | To DATE | To DATETIME | To TIMESTAMP | To TIME | To YEAR |
|---|---|---|---|---|---|---|
| Integer, floating-point, fixed-point, and BIT types | See rules for conversion within the category | Supported | Supported | Supported | Supported | Supported |
DATE |
Supported | See rules for conversion within the category | See rules for conversion within the category | See rules for conversion within the category | See rules for conversion within the category | See rules for conversion within the category |
DATETIME |
Supported | See rules for conversion within the category | See rules for conversion within the category | See rules for conversion within the category | See rules for conversion within the category | See rules for conversion within the category |
TIMESTAMP |
Supported | See rules for conversion within the category | See rules for conversion within the category | See rules for conversion within the category | See rules for conversion within the category | See rules for conversion within the category |
TIME |
Supported | See rules for conversion within the category | See rules for conversion within the category | See rules for conversion within the category | See rules for conversion within the category | See rules for conversion within the category |
YEAR |
Supported | See rules for conversion within the category | See rules for conversion within the category | See rules for conversion within the category | See rules for conversion within the category | See rules for conversion within the category |
Conversion between character data types and date and time data types
The following table describes the conversion between character data types and date and time data types.
| Data type | To CHAR, BINARY, VARCHAR, VARBINARY, TEXT types, and BLOB types | To ENUM and SET | To DATE | To DATETIME | To TIMESTAMP | To TIME | To YEAR |
|---|---|---|---|---|---|---|---|
CHAR, BINARY, VARCHAR, VARBINARY, TEXT types, and BLOB types |
See rules for conversion within the category | See rules for conversion within the category | Supported | Supported | Supported | Supported | Supported |
ENUM and SET |
See rules for conversion within the category | See rules for conversion within the category | Supported | Supported | Supported | Supported | Supported |
DATE |
Supported | Supported | See rules for conversion within the category | See rules for conversion within the category | See rules for conversion within the category | See rules for conversion within the category | See rules for conversion within the category |
DATETIME |
Supported | Supported | See rules for conversion within the category | See rules for conversion within the category | See rules for conversion within the category | See rules for conversion within the category | See rules for conversion within the category |
TIMESTAMP |
Supported | Supported | See rules for conversion within the category | See rules for conversion within the category | See rules for conversion within the category | See rules for conversion within the category | See rules for conversion within the category |
TIME |
Supported | Supported | See rules for conversion within the category | See rules for conversion within the category | See rules for conversion within the category | See rules for conversion within the category | See rules for conversion within the category |
YEAR |
Supported | Supported | See rules for conversion within the category | See rules for conversion within the category | See rules for conversion within the category | See rules for conversion within the category | See rules for conversion within the category |
Conversion to larger column types by using online DDL operations
Conversion between integer data types
| Data type | To SMALLINT | To MEDIUMINT | To INT | To BIGINT |
|---|---|---|---|---|
| TINYINT | Supported | Supported | Supported | Supported |
| SMALLINT | N/A | Supported | Supported | Supported |
| MEDIUMINT | Not supported | N/A | Supported | Supported |
| INT | Not supported | Not supported | N/A | Supported |
| Data type | To USMALLINT | To UMEDIUMINT | To UINT | To UBIGINT |
|---|---|---|---|---|
| UTINYINT | Supported | Supported | Supported | Supported |
| USMALLINT | N/A | Supported | Supported | Supported |
| UMEDIUMINT | Not supported | N/A | Supported | Supported |
| UINT | Not supported | Not supported | N/A | Supported |
DECIMAL/DECIMALINT
DECIMAL(precision, scala) is a decimal numeric data type. precision indicates the total length of a number, and scala indicates the number of digits in the fractional part. In online DDL operations, the ranges of precision are [1,9], [10,18], [19,38] and [39,65].
Notice
- In Oracle mode, the maximum value of
precisionis 38. - In MySQL mode, the maximum value of
precisionis 65.
You can perform an online DDL operation to convert a DECIMAL type into another DECIMAL type that provides a precision in the same range and has the same scala, because such conversion does not change the underlying physical storage. For example, you can perform an online DDL operation to convert the DECIMAL(10, 2) type into the DECIMAL(12, 2) type.
You can perform an online DDL operation to convert a DECIMAL type into another DECIMAL type with a larger
precision. For example, you can perform an online DDL operation to convert theDECIMAL(10, 2)type into theDECIMAL(12, 2)type. However, you can only perform an offline DDL operation to convert a DECIMAL type into another DECIMAL type with a smallerprecision. You can only perform an offline DDL operation to convert a DECIMAL type into another DECIMAL type with aprecisionin another range.You can only perform an offline DDL operation to convert a DECIMAL type into another DECIMAL type with a different
scala, no matter whether thescalais increased or decreased. For example, you must perform an offline DDL operation to convert theDECIMAL(10, 2)type into theDECIMAL(10, 4)type, or theDECIMAL(10, 2)type into theDECIMAL(10, 1)type.
Increase the length of a VARCHAR data type
You can perform an online DDL operation to convert the VARCHAR(x) type into the VARCHAR(y) type when y is greater than or equal to x. For example, you can perform an online DDL operation to convert the VARCHAR(10) type into the VARCHAR(20) type.
Increase the length of a VARBINARY data type
You can perform an online DDL operation to convert the VARBINARY(x) type into the VARBINARY(y) type when y is greater than or equal to x. For example, you can perform an online DDL operation to convert the VARBINARY(10) type into the VARBINARY(20) type.
LOB types
Notice
LOB columns cannot be used as indexed columns or primary key columns.
| Data type | To MEDIUMBLOB | To LONGBLOB |
|---|---|---|
| BLOB | Supported | Supported |
| MEDIUMBLOB | N/A | Supported |
| Data type | To MEDIUMTEXT | To LONGTEXT |
|---|---|---|
| TEXT | Supported | Supported |
| MEDIUMTEXT | N/A | Supported |
Conversion between VARCHAR and TINYTEXT
| Data type | To VARCHAR(x), x >= 255 | To TINYTEXT |
|---|---|---|
| TINYTEXT | Supported | N/A |
| VARCHAR(x), x <= 255 | N/A | Supported |
Conversion between VARBINARY and TINYBLOB
| Data type | To VARBINARY(x), x >= 255 | To TINYBLOB |
|---|---|---|
| TINYBLOB | Supported | N/A |
| VARBINARY(x), x <= 255 | N/A | Supported |