Skip to content

Simplest CTE indentation error #276

@benji-york

Description

@benji-york

I noticed several issues around CTEs and indentation. I.e.,

I don't want to pile on, but thought that an issue to track the simplest-possible version of the problem might help.

When I format this query (using the online formatter with default settings):

WITH foo AS (
    SELECT 1 WHERE (1 = 1)
    UNION ALL
    SELECT 1
)
SELECT 1;

I get:

WITH foo AS (
    SELECT
        1
    WHERE (1 = 1)
UNION ALL
SELECT
    1
)
SELECT
    1;

Which demonstrates the indentation issue starting with "UNION ALL".

If the parenthesis in the WHERE clause are removed, the indentation issue does not present. (Note how the clause is moved down and indented while it was on the same line as the WHERE in the previous output.)

WITH foo AS (
    SELECT
        1
    WHERE
        1 = 1
    UNION ALL
    SELECT
        1
)
SELECT
    1;

Looking back at the other issues, the presence of parenthesis may be significant in those as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions