WL#14015: Allow YEAR as type in the CAST function
Affects: Server-8.0
—
Status: Complete
MySQL does not allow CASTing to YEAR type. It is required for completeness of the type system and will be handled by this WL. By allowing the YEAR argument to the CAST function, it will be possible for arguments of any data type (except GEOMETRY) to be correctly converted to the YEAR data type. RAPID engine does not allow queries which have comparisons between arguments of different data types. This will make it possible for users to explicitly CAST arguments to YEAR in comparisons in order to be offloaded to RAPID. A follow up WL will make the implicit CASTs, that MySQL internally does at the moment, explicit, so that RAPID will behave the same as MySQL.
F1. If supplied with the YEAR type argument, the CAST function will have the YEAR data type. F2. It will only generate correct YEAR values: NULL, 0 or values in the range 1901 to 2155. F3. It will accept 4-digit numbers in the range 1901 to 2155 and will return the corresponding YEAR value. F4. It will accept strings that starts with a numeric digit and if the value interpreted as a number is in the range 1901 to 2155 it will return the corresponding YEAR value. If the string has some non-numeric digits at the end it will also return a ER_TRUNCATED_WRONG_VALUE warning. eg. "2010blabla" returns YEAR 2010 and warning. (For wrong values, see requirement F12.) F5. It will accept 1- or 2-digit numbers in the range 0 to 69 and it will convert the values 1 to 69 to the corresponding YEAR value in the range 2001 to 2069 (by adding 2000). 0 will return YEAR 0, not 2000. F6. It will accept strings that starts with a digit and if the value interpreted as a number is in the range 0 to 69 it will return the corresponding YEAR value in the range 2000 to 2069 (by adding 2000, even if the value is evaluated to 0, it will add 2000 to it, unlike F5.). If the string has some non-numeric digits at the end it will also return a ER_TRUNCATED_WRONG_VALUE F7. It will accept 2-digit numbers in the range 70 to 99 and it will convert the value to the corresponding YEAR value in the range 1970 to 1999 (by adding 1900). F8. It will accept strings that starts with a digit and if the value interpreted as a number is in the range 70 to 99 and it will return the corresponding YEAR value in the range 1970 to 1999 (by adding 1900). If the string has some non-numeric digits at the end it will also return a ER_TRUNCATED_WRONG_VALUE F9. It will return the YEAR part of DATE/DATETIME/TIME (for TIME it will first convert the argument to TIMESTAMP before returning the YEAR value which means it will return the current year). example 1: TIMESTAMP"2010-01-01 23:35:00" => 2010 example 2: TIME"20:01:00" => 2020 F10. GEOMETRY arguments will be rejected with ER_WRONG_ARGUMENTS error F11. DECIMAL, FLOAT/DOUBLE/REAL(s) will get rounded to the nearest integer before getting converted to YEAR. e.g. 1944.3 => 1944 F12. Wrong values will return NULL and ER_WRONG_VALUE warning. F13. ER_NOT_SUPPORTED_YET is returned in CAST to YEAR ARRAY. F14. JSON_VALUE will allow YEAR as a RETURNING data type. F15. JSON_VALUE will allow YEAR values as DEFAULT values. F16. Values that are wrong or out of range for RETURNING YEAR in JSON_VALUE, will respect the JSON_VALUE rules defined by the ON EMPTY and ON DEFAULT clauses. (if the same value would return warnings for CAST(), it will trigger the ON ERROR clause for JSON_VALUE, example: "1900.00") F17. DEFAULT YEAR values for JSON_VALUE that are out of range will return ER_DATA_OUT_OF_RANGE as other JSON_VALUE data types do. eg 1001 F18. DEFAULT YEAR values for JSON_VALUE that are wrong will return ER_TRUNCATED_WRONG_VALUE as other JSON_VALUE data types do. eg. "abc" or "1900.00" F19. Unlike CAST, JSON_VALUE rejects one/two digit number abbreviations.
mysql> select CAST("71" AS YEAR); Field 1: `CAST("71" AS YEAR)` Catalog: `def` Database: `` Table: `` Org_table: `` Type: YEAR Collation: binary (63) Length: 4 Max_length: 4 Decimals: 0 Flags: BINARY NUM +--------------------+ | CAST("71" AS YEAR) | +--------------------+ | 1971 | +--------------------+ 1 row in set (0,00 sec)
Copyright (c) 2000, 2024, Oracle Corporation and/or its affiliates. All rights reserved.