Data Type Conversion
On this page
The global sync variable data_ controls the way certain data conversions are performed.'7. level will fail the conversion of 'abc' to an integer value, while the '6. level will silently convert it to a NULL or 0.
The following table lists the data type conversion checks and behavior changes that are introduced with each data_ value.
|
data_ |
Data Type Conversion Checks |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
It’s recommended to set the data_ variable to the highest available value for new application development.data_ can change the behavior of expressions in computed columns.
If a computed column value changes due to a change in data_; columnstore sorting, indexes, and sharding can become logically corrupted.data_ or sql_ changes.
Note
sql_ is persisted to the CREATE TABLE statement.sql_ that the table is created with, which may be different from the current sql_.
Best Practices to Avoid Data Corruption
-
Review the computed column expressions when changing
data_.conversion_ compatibility_ level -
Perform application upgrade tests.
For example, if a computed column contains corrupted data and you have to switch to a higher data_, you may need to drop the computed column before changing the level.
The following examples demonstrate how the behavior of expressions may change if data_ is changed.
Example 1
SET GLOBAL data_conversion_compatibility_level = '6.0';
SELECT DATE('2019-04-20') + 2;
+------------------------+
| DATE('2019-04-20') + 2 |
+------------------------+
| 20190422 |
+------------------------+Example 2
SET GLOBAL data_conversion_compatibility_level = '7.0';
SELECT DATE('2019-04-20') + 2;
+------------------------+
| DATE('2019-04-20') + 2 |
+------------------------+
| 2019-04-22 |
+------------------------+The following example shows the error message generated if a zero value is attempted to be inserted into a DATE, DATETIME, or DATETIME(6) column if the data_ is set to 7. or higher.
SET GLOBAL data_conversion_compatibility_level = '7.0';
CREATE TABLE dates (dt DATETIME);INSERT INTO dates VALUES ('0000-00-00');
ERROR 2363 (HY000): Leaf Error: Invalid DATE/TIME in type conversionSee the table on the Time and Date page for examples of zero values for DATE, DATETIME, and DATETIME(6) data types.
Last modified: October 25, 2024