Column type change rules
When you change the column type in seekdb, you need to consider the column type change rules at the table level first, especially the scenarios where some data types are disabled. Then, consider the rules for changing the source data type to the target data type.
Column type change rules at the table level
Disabled rules
-
Foreign key constraints
For Online DDL and Offline DDL, except for the following special cases (note that the type modification only changes the display precision and does not change the storage structure), other scenarios do not support modifying the type of foreign key columns.
-
If the column data type is
FLOAT(m,n), the precision can be changed, butSIGNEDandUNSIGNEDcannot be converted to each other. -
If the column data type is
DOUBLE(m,n), the precision can be changed, butSIGNEDandUNSIGNEDcannot be converted to each other. -
If the column data type is
VARCHAR(m), the precision can be increased, but cannot be decreased, and cannot be changed to theCHARtype.
-
-
CHECKconstraintsFor Online DDL and Offline DDL, except for columns of the
INTEGERtype, columns withCHECKconstraints do not support type modification. -
Trigger constraints
For Offline DDL, when a column has a trigger constraint that is not
DISABLE, changing the column type is prohibited. If all triggers areDISABLE, it does not affect the DDL operation, and the new table must include thisDISABLEtrigger.
Change rules
-
When the data type length increases within the same data type, such as changing the data type of a column from
VARCHAR(8)toVARCHAR(11), this operation can be performed as an Online DDL without data rewrite.- If the column length is modified using Online DDL and the column has an index table (e.g., the length of a
VARCHARcolumn increases), the schema of the index table and related dependent objects must also be modified during the Online DDL operation. That is, "the user expects the data to remain unchanged, but the schema of the dependent objects must also be modified." - For columns of the
INTEGERandDecimalInttypes, if they are indexed or primary key columns, the column type growth operation can be performed using Online DDL.
- If the column length is modified using Online DDL and the column has an index table (e.g., the length of a
-
In seekdb, for the growth of the
LOBtype, Online DDL operations support the following scenarios:- Modification of regular columns.
- Modification of generated columns (Store/Virtual).
- Modification of columns that depend on generated columns (Store/Virtual).
- Adding
NOT NULLandCHECKconstraints. - Modifying existing
NOT NULLconstraints.
-
For numeric data types, if a conversion between
SIGNEDandUNSIGNEDoccurs, an Offline operation must be performed if type changes are allowed. For character data types, if a change in character set and collation occurs, an Offline operation must be performed if column type changes are allowed. -
When a column is referenced by a generated column, column type changes are allowed.
Column conversion rules
In seekdb, all column data types are divided into three major categories: numeric data types, character data types, and time data types. The conversion rules within each category 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 category.
Conversion between numeric data types
Numeric data types are divided into the following categories:
-
Integer:
TINYINT,SMALLINT,MEDIUMINT,INT,BIGINT -
Floating-point:
FLOAT,DOUBLE -
Fixed-point:
NUMBER -
Binary:
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 |
Conversions between character data types
Character data types are divided into the following categories:
-
CHARandVARCHAR -
BINARYandVARBINARY -
TEXTdata types:TINYTEXT,MEDIUMTEXT,TEXT, andLONGTEXT -
BLOBdata types:TINYBLOB,MEDIUMBLOB,BLOB, andLONGBLOB -
ENUMandSET
The following table describes the conversions between 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 types
The time data types include:
-
DATE -
TIMESTAMP -
DATETIME -
TIME -
YEAR
The following table describes the conversions within the 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 and character data types
The following table describes the conversion between numeric and character data types.
| Data type | To integer, float, and decimal types | To BIT type | To CHAR, BINARY, VARCHAR, VARBINARY, TEXT, and BLOB types | To ENUM and SET types |
|---|---|---|---|---|
| Integer, float, and decimal 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 | See the conversion rules in the corresponding category. | See the conversion rules in the corresponding category. |
Conversion between numeric and time categories
The following table describes the conversion between numeric and time categories.
| Data type | To integer, float, decimal, or BIT | To DATE | To DATETIME | To TIMESTAMP | To TIME | To YEAR |
|---|---|---|---|---|---|---|
Integer, floating-point, fixed-point, and BIT types | 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 | For more information, see the conversion rules in the corresponding category. | For more information, see the conversion rules in the corresponding category. | For more information, see the conversion rules in the corresponding category. | For more information, see the conversion rules in the corresponding category. | For more information, see the conversion rules in the corresponding category. |
TIME | Supported | For more information, see the conversion rules in the corresponding category. | For more information, see the conversion rules in the corresponding category. | For more information, see the conversion rules in the corresponding category. | For more information, see the conversion rules in the corresponding category. | For more information, see the conversion rules in the corresponding category. |
YEAR | Supported | See the conversion rules in the category. | See the conversion rules in the category. | See the conversion rules in the category. | See the conversion rules in the category. | See the conversion rules in the category. |
Conversion between character classes and time classes
The following table describes the conversion between character classes and time classes.
| 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 types | See the conversion rules within each category. | See the conversion rules within each category. | Supported | Supported | Supported | Supported | Supported |
ENUM, SET | Yes | Yes | Yes | Yes | Yes | ||
DATE | Supported | Supported | See the conversion rules in the category. | See the conversion rules in the category. | See the conversion rules in the category. | See the conversion rules in the category. | See the conversion rules in the category. |
DATETIME | Supported | Supported | See the conversion rules in the category. | See the conversion rules in the category. | See the conversion rules in the category. | See the conversion rules in the category. | See the conversion rules in the category. |
TIMESTAMP | Supported | Supported | For conversion rules, see the conversion rules in the corresponding major category. | For conversion rules, see the conversion rules in the corresponding major category. | For conversion rules, see the conversion rules in the corresponding major category. | For conversion rules, see the conversion rules in the corresponding major category. | For conversion rules, see the conversion rules in the corresponding major category. |
TIME | Supported | Supported | For conversion rules, see the conversion rules in the corresponding major category. | For conversion rules, see the conversion rules in the corresponding major category. | For conversion rules, see the conversion rules in the corresponding major category. | For conversion rules, see the conversion rules in the corresponding major category. | For conversion rules, see the conversion rules in the corresponding major 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 scenarios for column type conversion
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 specifies the total length of the number, and scala specifies the number of decimal places. The precision of DECIMAL in Online DDL operations can be in the range [1, 9], [10, 18], [19, 38], or [39, 65].
In seekdb, the maximum value of precision is 65.
If the precision value is within the same range and the scala value remains unchanged, the underlying physical storage does not change, and you can use Online DDL to modify the column. For example, you can use Online DDL to change a DECIMAL(10, 2) column to a DECIMAL(12, 2) column.
-
If the first parameter
precisionchanges, you can use Online DDL to increase theprecisionvalue. For example, you can use Online DDL to change aDECIMAL(10, 2)column to aDECIMAL(12, 2)column. However, if theprecisionvalue decreases, you cannot use Online DDL to modify the column. In this case, you must use Offline DDL. If theprecisionvalue changes across ranges, you must use Offline DDL. -
If the second parameter
scalachanges, you must use Offline DDL to modify the column. In other words, you cannot use Online DDL. For example, you must use Offline DDL to change aDECIMAL(10, 2)column to aDECIMAL(10, 4)column or to aDECIMAL(10, 1)column.
VARCHAR type conversion
You can use Online DDL to change a VARCHAR(x) column to a VARCHAR(y) column, provided that y is greater than or equal to x. For example, you can use Online DDL to change a VARCHAR(10) column to a VARCHAR(20) column.
VARBINARY type conversion
You can use Online DDL to change a VARBINARY(x) column to a VARBINARY(y) column, provided that y is greater than or equal to x. For example, you can use Online DDL to change a VARBINARY(10) column to a VARBINARY(20) column.
Large object (LOB) type conversion
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 |
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 |