You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
SQL Formatter Does Not Properly Indent UNION Queries and Derived Tables #1698
The SQL formatter does not correctly format queries that contain a UNION inside a derived table (subquery in the FROM clause).
Instead of maintaining consistent indentation and formatting for nested queries, the formatter collapses parts of the query and places the closing parenthesis directly after the final SELECT, reducing readability.
Steps to Reproduce
Open the SQL editor.
Paste the following query:
SELECT
country,
avg(happiness_score) AS happiness_score
FROM
(
SELECT
YEAR,
country,
happiness_score
FROM
happiness_scores
UNIONSELECT2024,
country,
ladder_score
FROM
happiness_scores_current
) AS final
GROUP BY
country;
Run the SQL formatter.
Expected Result
SELECT
country,
avg(happiness_score) AS happiness_score
FROM
(
SELECT
YEAR,
country,
happiness_score
FROM
happiness_scores
UNIONSELECT2024,
country,
ladder_score
FROM
happiness_scores_current
) AS final
GROUP BY
country;
The formatter should preserve indentation for the derived table and align the UNION query blocks consistently.
Actual Result
SELECT country,
avg(happiness_score) AS happiness_score
FROM (
SELECT YEAR,
country,
happiness_score
FROM happiness_scores
UNIONSELECT2024,
country,
ladder_score
FROM happiness_scores_current) AS final
GROUP BY country;
Activity
fix(editor): keep nested indentation for set operations in subqueries…
fix(editor): keep nested indentation for set operations in subqueries…