tconbeer / sqlfmt

sqlfmt formats your dbt SQL files so you don't have to
https://sqlfmt.com
Apache License 2.0
402 stars 16 forks source link

Broken sql format with many long column names #477

Closed a0th closed 1 year ago

a0th commented 1 year ago

Describe the bug The sql is broken after formatting.

To Reproduce The code below:

with
    cte1 as (select * from {{ ref("model1") }}),
    cte2 as (select * from {{ ref("model2") }}),
    cte3 as (
        select
            cte2.*,
            this_column
            - that_super_long_long_column_name
             as super_long_column_name,
            another_long_column_name,
            this_column,
            yet_another_column
        from cte2
        left join cte1 using (project_id)
    )
select *
from cte3

Once formatted turns into this:

with
    cte1 as (select * from {{ ref("model1") }}),
    cte2 as (select * from {{ ref("model2") }}),
    cte3 as (
        select
            cte2.*,
            this_column - that_super_long_long_column_name as super_long_column_name,
            another_long_column_name,
            this_column,
            yet_another_column
        left join cte1 using (project_id)
    )
        from cte2
select *
from cte3

The from cte2 statement is removed from the cte3 definition.

Additional context sqlfmt, version 0.19.0

tconbeer commented 1 year ago

See my comment on your other issue. I'm almost certain it's not my software doing this.

a0th commented 1 year ago

See https://github.com/tconbeer/sqlfmt/issues/476, this is apparently a problem with dbt power user on VSCode.