jodotlearn opened a new issue, #4108: URL: https://github.com/apache/doris-website/issues/4108
https://doris.apache.org/docs/3.x/sql-manual/sql-functions/scalar-functions/date-time-functions/date-trunc The `DATE_TRUNC` documentation states that both argument orders are supported: ```sql DATE_TRUNC(<datetime>, <time_unit>) DATE_TRUNC(<time_unit>, <datetime>) ``` However, in actual usage, only the following argument order appears to work: ```sql DATE_TRUNC(<datetime>, <time_unit>) ``` The reversed form: ```sql DATE_TRUNC(<time_unit>, <datetime>) ``` results in an error. ## Reproduction ### Case 1: Using a DATETIME column The datetime-first form works as expected: ```sql SELECT DATE_TRUNC(work_date, 'month'); ``` However, reversing the arguments: ```sql SELECT DATE_TRUNC('month', work_date); ``` returns: ```text SQL Error [1105] [HY000]: errCode = 2, detailMessage = the second parameter of date_trunc function must be a string constant: date_trunc('month', work_date) ``` This suggests that the second argument is still interpreted as `time_unit`. ### Case 2: Using only string literals The same behavior can be reproduced without using a column: ```sql SELECT DATE_TRUNC('month', '2010-12-02 19:28:30'); ``` which returns: ```text SQL Error [1105] [HY000]: errCode = 2, detailMessage = date_trunc function second param only support argument is year|quarter|month|week|day|hour|minute|second ``` Again, this indicates that the second argument is interpreted as `time_unit`, rather than the first argument. In contrast, the datetime-first form works: ```sql SELECT DATE_TRUNC('2010-12-02 19:28:30', 'month'); ``` ## Expected behavior According to the documentation, both forms should be accepted: ```sql DATE_TRUNC(work_date, 'month') DATE_TRUNC('month', work_date) ``` ## Actual behavior Only the datetime-first form appears to be supported: ```sql DATE_TRUNC(<datetime>, <time_unit>) ``` ## Question Could you please confirm whether: 1. `DATE_TRUNC(<time_unit>, <datetime>)` is intended to be supported; or 2. the documentation should only list: ```sql DATE_TRUNC(<datetime>, <time_unit>) ``` If the reversed argument order is only supported in specific Doris versions, it would also be helpful to clarify the supported versions in the documentation. ## Environment Apache Doris version: 3.0.4 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
