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:
DATE_TRUNC(<datetime>, <time_unit>)
DATE_TRUNC(<time_unit>, <datetime>)
However, in actual usage, only the following argument order appears to work:
DATE_TRUNC(<datetime>, <time_unit>)
The reversed form:
DATE_TRUNC(<time_unit>, <datetime>)
results in an error.
Reproduction
Case 1: Using a DATETIME column
The datetime-first form works as expected:
SELECT DATE_TRUNC(work_date, 'month');
However, reversing the arguments:
SELECT DATE_TRUNC('month', work_date);
returns:
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:
SELECT DATE_TRUNC('month', '2010-12-02 19:28:30');
which returns:
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:
SELECT DATE_TRUNC('2010-12-02 19:28:30', 'month');
Expected behavior
According to the documentation, both forms should be accepted:
DATE_TRUNC(work_date, 'month')
DATE_TRUNC('month', work_date)
Actual behavior
Only the datetime-first form appears to be supported:
DATE_TRUNC(<datetime>, <time_unit>)
Question
Could you please confirm whether:
-
DATE_TRUNC(<time_unit>, <datetime>) is intended to be supported; or
-
the documentation should only list:
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
https://doris.apache.org/docs/3.x/sql-manual/sql-functions/scalar-functions/date-time-functions/date-trunc
The
DATE_TRUNCdocumentation states that both argument orders are supported:However, in actual usage, only the following argument order appears to work:
The reversed form:
results in an error.
Reproduction
Case 1: Using a DATETIME column
The datetime-first form works as expected:
However, reversing the arguments:
returns:
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:
which returns:
Again, this indicates that the second argument is interpreted as
time_unit, rather than the first argument.In contrast, the datetime-first form works:
Expected behavior
According to the documentation, both forms should be accepted:
Actual behavior
Only the datetime-first form appears to be supported:
Question
Could you please confirm whether:
DATE_TRUNC(<time_unit>, <datetime>)is intended to be supported; orthe documentation should only list:
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