Bug #121182 Temporal BETWEEN conversion-failure error message blames the valid constant instead of the failing operand
Submitted: 28 Aug 8:05 Modified: 29 Aug 19:29
Reporter: Chunling Qin Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server: DML Severity:S3 (Non-critical)
Version:9.7.2 OS:Any
Assigned to: CPU Architecture:Any

[28 Aug 8:05] Chunling Qin
Description:
When a numeric LHS cannot be converted to DATETIME and BETWEEN is evaluated via the compare_as_datetimes_with_strings path, the raised error names the perfectly valid constant instead of the operand that actually failed to convert:

SET sql_mode='';
SELECT 1e300 BETWEEN TIMESTAMP'2024-01-01' AND TIMESTAMP'2030-01-01'];
-- ERROR 1525 (HY000): Incorrect DATETIME value: '2024-01-01'
'2024-01-01' is a fully valid literal; the actual failure is the conversion of 1e300 (LHS) to DATETIME. A user following the message would inspect the constant instead of the LHS expression/column.

Additionally the error is raised even with sql_mode='' (non-strict), while the TIME-bounds variant of the same query shape is silent (see companion report BUG-M1), so error behavior is also inconsistent across temporal types.

How to repeat:
SET sql_mode='';
SELECT 1e300 BETWEEN TIMESTAMP'2024-01-01' AND TIMESTAMP'2030-01-01'];
-- ERROR 1525 (HY000): Incorrect DATETIME value: '2024-01-01'   <-- blames the constant

SELECT 'abc' BETWEEN DATE'2024-01-01' AND DATE'2030-01-01'];
-- ERROR 1525 (HY000): Incorrect DATE value: 'abc'              <-- raised in non-strict mode

SELECT 'abc' BETWEEN TIME'00:00:00' AND TIME'23:59:59';
-- no error (silent 0)                                          <-- inconsistent

Suggested fix:
In the error-reporting path of Item_func_between::val_int() / Arg_comparator temporal handling, reference the operand whose conversion failed (args[0], the LHS) rather than the constant bound. Align strict/non- strict behavior with the rest of the temporal comparison paths (non-strict should degrade to warning + NULL).
[29 Aug 19:29] Roy Lyseng
Thank you for the bug report.

However, this is not a bug.

TIMESTAMP'2024-01-01' is not a valid TIMESTAMP literal, as it contains only a DATE component but no TIME component.

Substituting TIMESTAMP with DATE would make this a valid query.