When changing the column type in a table in OceanBase Database in MySQL mode, you must first consider the column type change rules at the table level, especially for some disabled data types. Then, consider the change rules for the source and target data types during the column type change.
Column type change rules at the table level
Disabled rules
Foreign key constraints
For Online DDL and Offline DDL, column type changes are not supported in the following scenarios (note that the type modifications only change the display precision and do not affect the storage structure):
If the column's data type is
FLOAT(m,n), precision changes are supported, but conversion betweenSIGNEDandUNSIGNEDis not.If the column's data type is
DOUBLE(m,n), precision changes are supported, but conversion betweenSIGNEDandUNSIGNEDis not.If the column's data type is
VARCHAR(m), increasing the precision is supported, but decreasing it is not, and changing it to theCHARtype is also not supported.
CHECKconstraintsFor Online DDL and Offline DDL, column type changes are not supported for columns with
CHECKconstraints, except for columns of theINTEGERtype.Trigger constraints
For Offline DDL, column type changes are not supported if the column has a non-
DISABLEtrigger constraint. If all triggers areDISABLE, the DDL operation is not affected, and the new table must include theDISABLEtrigger.
Change rules
When the data type remains the same but the length increases, for example, changing a column's data type from
VARCHAR(8)toVARCHAR(11), this operation can be performed as an Online DDL without requiring data rewrites.- If you modify the column length using Online DDL and the column has an index table (e.g., increasing the length of a
VARCHARcolumn), you must also update the schema of the index table and other dependent objects during the Online DDL operation. This means that the user's data should remain unchanged, but the schema of dependent objects must also be updated. - For columns of the
INTEGERorDecimalInttype, if they are indexed or primary key columns, the column type growth can be performed using Online DDL.
- If you modify the column length using Online DDL and the column has an index table (e.g., increasing the length of a
In OceanBase Database, Online DDL operations support the following scenarios for
LOBtype growth:- Modifying regular columns.
- Modifying generated columns (store/virtual).
- Modifying columns that are dependent on generated columns (store/virtual).
- Adding
NOT NULLandCHECKconstraints. - Modifying existing
NOT NULLconstraints.
For numeric data types, if a conversion between
SIGNEDandUNSIGNEDis required, an Offline DDL operation must be performed. For character data types, if a change in character set or collation is required, an Offline DDL operation must also be performed.If a column is referenced by a generated column, column type changes are allowed.
Column conversion rules
In OceanBase Database, all column data types are divided into three major categories: numeric data types, character data types, and datetime data types. The conversion rules within each of these categories are similar, and the conversion rules between different categories are also similar. However, there are some special cases.
The following tables list the conversion rules within and between each of these categories.
Conversion between numeric data types
Numeric data types are categorized as follows:
Integer types:
TINYINT,SMALLINT,MEDIUMINT,INT, andBIGINTFloating-point types:
FLOATandDOUBLEFixed-point types:
NUMBERBinary types:
BIT
The following table describes the conversion between numeric data types.
| Data type | To TINYINT、SMALLINT、MEDIUMINT、INT、BIGINT | To FLOAT、DOUBLE | To NUMBER | To BIT |
|---|---|---|---|---|
| Integer | Supported | Supported | Supported | Supported |
| Floating-point | Supported | Supported | Supported | Supported |
| Fixed-point | Supported | Supported | Supported | Supported |
| Binary | Supported | Supported | Supported | Supported |
Conversion within character data types
Character data types are categorized as follows:
CHARandVARCHARBINARYandVARBINARYTEXTtypes:TINYTEXT,MEDIUMTEXT,TEXT, andLONGTEXTBLOBtypes:TINYBLOB,MEDIUMBLOB,BLOB, andLONGBLOBENUMandSET
The following table describes the conversions within character data types.
| Data type | To CHAR | To BINARY | To VARCHAR\ VARBINARY | To TEXT\ BLOB | To ENUM\ SET |
|---|---|---|---|---|---|
CHAR |
Supported | Supported | Supported | Supported | Supported |
BINARY |
Supported | Supported | Supported | Supported | Supported |
VARCHAR, VARBINARY |
Supported | Supported | Supported | Supported | Supported |
TEXT large types, BLOB large types |
Supported | Supported | Supported | Supported | Supported |
ENUM, SET |
Supported | Supported | Supported | Supported | Supported |
Conversions within the time data type category
Time data types include:
DATETIMESTAMPDATETIMETIMEYEAR
The following table shows the conversions within the time data type category.
| 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 and character categories
The conversion between numeric and character categories is shown in the following table.
| Data type | To integer, floating-point, and fixed-point types | To BIT type | To CHAR, BINARY, VARCHAR, VARBINARY, TEXT, and BLOB types | To ENUM and SET types |
|---|---|---|---|---|
| Integer, floating-point, and fixed-point types | See the conversion rules within the category. | See the conversion rules within the category. | Supported | Supported |
BIT type |
See the conversion rules within the category. | See the conversion rules within the category. | Supported | Supported |
CHAR, BINARY, VARCHAR, VARBINARY, TEXT, and BLOB types |
Supported | Supported | See the conversion rules within the category. | Supported |
ENUM and SET |
Yes | Yes | For conversion rules in this category, see the conversion rules in the category. | For conversion rules in this category, see the conversion rules in the category. |
Conversion between numeric and temporal categories
The following table shows the conversion between numeric and temporal categories.
| Data type | To integer, float, decimal, and BIT |
To DATE | To DATETIME | To TIMESTAMP | To TIME | To YEAR |
|---|---|---|---|---|---|---|
Integer, float, decimal, and BIT |
See the conversion rules in the corresponding category. | Supported | Supported | Supported | Supported | Supported |
DATE |
Supported | See the conversion rules in the corresponding category. | See the conversion rules in the corresponding category. | See the conversion rules in the corresponding category. | See the conversion rules in the corresponding category. | See the conversion rules in the corresponding category. |
DATETIME |
Supported | See the conversion rules in the corresponding category. | See the conversion rules in the corresponding category. | See the conversion rules in the corresponding category. | See the conversion rules in the corresponding category. | See the conversion rules in the corresponding category. |
TIMESTAMP |
Supported | See the conversion rules in the corresponding category. | See the conversion rules in the corresponding category. | See the conversion rules in the corresponding category. | See the conversion rules in the corresponding category. | See the conversion rules in the corresponding category. |
TIME |
Supported | See the conversion rules in the corresponding category. | See the conversion rules in the corresponding category. | See the conversion rules in the corresponding category. | See the conversion rules in the corresponding category. | See the conversion rules in the corresponding category. |
YEAR |
Supported | See the conversion rules in the major category. | See the conversion rules in the major category. | See the conversion rules in the major category. | See the conversion rules in the major category. | See the conversion rules in the major category. |
Conversion between character and temporal types
The following table describes the conversion between character and temporal types.
| Data type | To CHAR, BINARY, VARCHAR, VARBINARY, TEXT, and BLOB types | To ENUM and SET types | To DATE | To DATETIME | To TIMESTAMP | To TIME | To YEAR | |
|---|---|---|---|---|---|---|---|---|
CHAR, BINARY, VARCHAR, VARBINARY, TEXT, and BLOB |
See the conversion rules in the corresponding category. | See the conversion rules in the corresponding category. | Supported | Supported | Supported | Supported | Supported | Supported |
ENUM and SET |
See the conversion rules in the corresponding category. | See the conversion rules in the corresponding category. | Supported | Supported | Supported | Supported | Supported | |
DATE |
Supported | Supported | See the conversion rules in the corresponding data type category. | See the conversion rules in the corresponding data type category. | See the conversion rules in the corresponding data type category. | See the conversion rules in the corresponding data type category. | See the conversion rules in the corresponding data type category. | |
DATETIME |
Supported | Supported | See the conversion rules in the corresponding data type category. | See the conversion rules in the corresponding data type category. | See the conversion rules in the corresponding data type category. | See the conversion rules in the corresponding data type category. | See the conversion rules in the corresponding data type category. | |
TIMESTAMP |
Supported | Supported | For conversion rules in the corresponding category. | For conversion rules in the corresponding category. | For conversion rules in the corresponding category. | For conversion rules in the corresponding category. | For conversion rules in the corresponding category. | |
TIME |
Supported | Supported | For conversion rules in the corresponding category. | For conversion rules in the corresponding category. | For conversion rules in the corresponding category. | For conversion rules in the corresponding category. | For conversion rules in the corresponding category. | |
YEAR |
Supported | Supported | See the conversion rules in the corresponding category. | See the conversion rules in the corresponding category. | See the conversion rules in the corresponding category. | See the conversion rules in the corresponding category. | See the conversion rules in the corresponding category. |
Online DDL column type upcasting scenarios
Integer type conversion
| 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) specifies a decimal number type, where precision represents the total length of the number, and scala represents the number of decimal places. During Online DDL, the precision of DECIMAL can be in the range [1, 9], [10, 18], [19, 38], or [39, 65].
Notice
- In Oracle mode, the maximum value of
precisionis 38. - In MySQL mode, the maximum value of
precisionis 65.
If the precision value is within the same range and the scala value remains unchanged, the underlying physical storage will not change. You can use Online DDL to modify the column type. For example, you can use Online DDL to change the column type from DECIMAL(10, 2) to DECIMAL(12, 2).
For changes to the first parameter
precision, if the length increases (i.e., theprecisionvalue increases), you can use Online DDL to modify the column type. For example, you can use Online DDL to change the column type fromDECIMAL(10, 2)toDECIMAL(12, 2). However, if the length decreases (i.e., theprecisionvalue decreases), you cannot use Online DDL to modify the column type. You must use Offline DDL. Cross-range changes also require Offline DDL.For changes to the second parameter
scala, whether the value increases or decreases, you must use Offline DDL to modify the column type. You cannot use Online DDL. For example, you must use Offline DDL to change the column type fromDECIMAL(10, 2)toDECIMAL(10, 4)or fromDECIMAL(10, 2)toDECIMAL(10, 1).
VARCHAR type
If you want to change the column type from VARCHAR(x) to VARCHAR(y), you can use Online DDL to modify the column type as long as the length of y is greater than or equal to the length of x. For example, you can use Online DDL to change the column type from VARCHAR(10) to VARCHAR(20).
VARBINARY type
If you want to change the column type from VARBINARY(x) to VARBINARY(y), you can use Online DDL to modify the column type as long as the length of y is greater than or equal to the length of x. For example, you can use Online DDL to change the column type from VARBINARY(10) to VARBINARY(20).
Large data types
Notice
LOB columns cannot be used as indexes or primary keys.
| 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 |
VARCHAR and TINYTEXT types
| Data type | To VARCHAR(x), x >= 255 | To TINYTEXT |
|---|---|---|
| TINYTEXT | Supported | N/A |
| VARCHAR(x), x <= 255 | N/A | Supported |
VARBINARY and TINYBLOB types
| Data type | To VARBINARY(x), x >= 255 | To TINYBLOB |
|---|---|---|
| TINYBLOB | Supported | N/A |
| VARBINARY(x), x <= 255 | N/A | Supported |
