Skip to content

Bad indentation with subquery inside nested paratheses #391

Description

@RasmusRendal

The following query:

SELECT
    *
FROM
    some_table
WHERE
    AND (row2 = 'b'
        OR row3 = 'c'
        OR EXISTS (
            SELECT
                1
            FROM
                some_table
            WHERE
                row4 = 'd')
        OR (row4 = 'e'));

Gets formatted by pgFormatter 8d0290b as:

SELECT
    *
FROM
    some_table
WHERE
    row1 = 'a'
    AND (row2 = 'b'
        OR row3 = 'c'
        OR EXISTS (
            SELECT
                1
            FROM
                some_table
            WHERE
                row4 = 'd')
            OR (row4 = 'e'));

The final OR (row4 = 'e') gets indented one level further to the right than OR row3 = 'c', even though they are part of the same disjunction.

If the OR EXISTS (SELECT 1 FROM some_table WHERE row4 = 'd') part of the query gets deleted, OR (row4 = 'e') gets moved back one indentation level.

This bug only occurs if the disjunction is inside a parenthesis. If the parenthesis is removed, the indentation works as expected.

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