Skip to content

DATE_TRUNC documentation is inconsistent with actual argument order behavior #4108

Description

@jodotlearn

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:

  1. DATE_TRUNC(<time_unit>, <datetime>) is intended to be supported; or

  2. 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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions