Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Union gets improperly indented #188

Closed
Rainymood opened this issue Jun 2, 2022 · 3 comments · Fixed by #194
Closed

Union gets improperly indented #188

Rainymood opened this issue Jun 2, 2022 · 3 comments · Fixed by #194
Labels
bug Something isn't working
Milestone

Comments

@Rainymood
Copy link

Rainymood commented Jun 2, 2022

Describe the bug
I believe that union gets improperly indented. The first and second blocks are of the same "importance" but union indents it because I assume it thinks it's a function and the opening parentheses (() at the start. I think this is a bug.

To Reproduce
Paste the query in http://sqlfmt.com/

Input code

(
    select *
    from "data_warehouse"."order_status"
    where var1 is not null and var2 is not null
    limit 100
)
union
    (
        select *
        from "data_warehouse"."order_status"
        where var1 is not null and var2 is not null
        limit 100
    )

Expected behavior

(
    select *
    from "data_warehouse"."order_status"
    where var1 is not null and var2 is not null
    limit 100
)
union
(
    select *
    from "data_warehouse"."order_status"
    where var1 is not null and var2 is not null
    limit 100
)

Actual behavior

(
    select *
    from "data_warehouse"."order_status"
    where var1 is not null and var2 is not null
    limit 100
)
union
    (
        select *
        from "data_warehouse"."order_status"
        where var1 is not null and var2 is not null
        limit 100
    )
@tconbeer
Copy link
Owner

tconbeer commented Jun 2, 2022

Thanks for the report! union is formatted properly if the second query is not wrapped in parentheses, but I agree with you that this is a bug, and the second query should not be indented

@tconbeer tconbeer added the bug Something isn't working label Jun 2, 2022
@tconbeer
Copy link
Owner

tconbeer commented Jun 2, 2022

To fix this I think we should create a new token type, SET_OPERATOR to distinguish union from a normal unterminated keyword like select. Then we update the logic for mutating open_brackets so that set operators don't get added to that list (but do have the existing behavior of popping existing unterminated keywords)

@Rainymood
Copy link
Author

Cheers! Such a fast fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants