Skip to content

【SQL Format】Incorrect Formatting for Year From #399

@xterao

Description

@xterao

Describe the bug
In PostgreSQL, year is treated as a reserved keyword, while in MySQL it is used as a function name.
When writing SQL in the PostgreSQL style such as extract(year from column_name), the FROM inside the parameter is incorrectly recognized as a clause, which introduces unwanted line breaks.

Additionally, when this function is used inside a conditional loop directive, the indentation of the function increases unexpectedly.

Example (current behavior):

SELECT
       /*%if groupByDepartment */
       d.department_name
        ,
       /*%end*/
       /*%if groupByLocation */
       d.location
        ,
       /*%end*/
                                                                                                                                                                                                               /*%if groupByYear */
                                                                                                                                                                                                               extract
                                                                                                                                                                                                               (YEAR
  FROM e.hire_date
       , x) AS hire_year
                                                                                                                                                                                                                ,
                                                                                                                                                                                                               /*%end*/                                                                                                                                                                                                                                                                                                                                                COUNT(*) AS employee_count
       , AVG(s.salary_amount) AS avg_salary

Expected behavior
For cases like extract(year from column_name), the parameters should be formatted inline, without introducing unintended line breaks.

Desktop :

  • IDEA Version : 2024.3.6
  • Doma Tools Version : 2.1.1

Additional context
he excessive indentation is not limited to the year from parameter. It can also occur with other parameter specifications when conditional loop directives are used alongside preceding column blocks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions