pgFormatter
pgFormatter copied to clipboard
Simplest CTE indentation error
I noticed several issues around CTEs and indentation. I.e.,
- #258
- #213
- #202
- #195
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.