matrixorigin / matrixorigin/matrixone
[Compatibility]: STR_TO_DATE rejects a prepared format-string parameter
- Dominant language
- Go
- Stars
- 1.9k
- Forks
- 311
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 768
Description
## Summary
`STR_TO_DATE` rejects a parameter marker in its format-string position during prepared-statement creation. The input value may be parameterized, and the related `DATE_FORMAT`/`TIME_FORMAT` functions accept parameterized format strings, so applications cannot reuse a `STR_TO_DATE` plan when its parsing format is runtime data.
## Environment
- MatrixOne official `main`: `99ed717b769e261b842c2f17345bd65865fc1470`
- Clean local single-CN build and isolated data directory
- Reproduced identically in 3/3 runs through both server-side text PREPARE and the MySQL binary prepared-statement protocol
## Reproduction
```sql
SELECT STR_TO_DATE('2024-01-02 01:02:03.654321', '%Y-%m-%d %H:%i:%s.%f');
-- 2024-01-02 01:02:03.654321
PREPARE p_value FROM
'SELECT STR_TO_DATE(?, ''%Y-%m-%d %H:%i:%s.%f'')';
SET @value = '2024-01-02 01:02:03.654321';
EXECUTE p_value USING @value;
-- 2024-01-02 01:02:03.654321
PREPARE p_format FROM
'SELECT STR_TO_DATE(''2024-01-02 01:02:03.654321'', ?)';
```
Actual result for `p_format`:
```text
ERROR 20203 (HY000): invalid argument str_to_date function have invalid input args length, bad value 2
```
Parameterizing both positions fails for the same reason.
## Scope control
```sql
PREPARE date_format FROM
'SELECT DATE_FORMAT(''2024-01-02 01:02:03.654321'', ?)';
SET @fmt = '%Y-%m-%d %H:%i:%s.%f';
EXECUTE date_format USING @fmt;
-- 2024-01-02 01:02:03.654321
PREPARE time_format FROM
'SELECT TIME_FORMAT(''01:02:03.654321'', ?)';
EXECUTE time_format USING @fmt;
-- 01:02:03.654321
```
## Expected behavior
The format string is a value expression and should be bindable in a prepared statement. `STR_TO_DATE(literal, ?)` and `STR_TO_DATE(?, ?)` should prepare and execute with each supplied format.
## Preliminary code observation
The binder derives `STR_TO_DATE`'s return type from the format and appends an internal third type marker. For an unknown format parameter it appends a `DATETIME` marker, but the prepared binding flow appears to validate the rewritten three-argument form as if it were the original public two-argument call. This is a diagnosis hypothesis, not a proposed fix.
## Suggested regression coverage
Cover server-side and binary prepared `STR_TO_DATE` with parameterized value, parameterized format, and both; include date-only, datetime(6), and time-only format outputs. Keep `DATE_FORMAT`/`TIME_FORMAT` dynamic-format cases as controls.
Contributor guide
Assessment
This issue has not been assessed yet.