sqlfluff / vscode-sqlfluff

An extension to use the sqlfluff linter in vscode.
https://marketplace.visualstudio.com/items?itemName=dorzey.vscode-sqlfluff
MIT License
156 stars 33 forks source link

Sql fluff garbles correct syntax #162

Closed theking2 closed 1 week ago

theking2 commented 1 week ago

After formatting with sqlfluff it turned

this

select 
    CONCAT_WS(
    ' ', ITEMNR, report_sales_100.DESCRIPTION
    ) as `Artikel Nr.`, 
    PHYSICIAN, 
    BATCHID, 
    INVOICENR, 
    sum(Quantity) / _c.`count` Menge 
from invoice_physician 
join report_sales_100 using(INVOICENR) 
join product_with_family using(ITEMNR) 
join (
    select 
        INVOICENR, 
        count(PHYSICIAN) `count` 
    from 
        invoice_physician 
    group by 
        INVOICENR
) _c using(INVOICENR) 
group by 
    ITEMNR, 
    PHYSICIAN, 
    BATCHID 
order by 
    ITEMNR, 
    PHYSICIAN, 
    BATCHID;

into this

with _C as (
    select
        INVOICENR,
        COUNT(PHYSICIAN) as `count`
    from
        INVOICE_PHYSICIAN
    group by
        INVOICENR
)
select
    PHYSICIAN,
    BATCHID,
    INVOICENR,
    CONCAT_WS(
        ' ', ITEMNR, REPORT_SALES_100.DESCRIPTION
    ) as `Artikel Nr.`,
    SUM(QUANTITY) / _C.`count` as MENGE
from INVOICE_PHYSICIAN
inner join
    REPORT_SALES_100
    on INVOICE_PHYSICIAN.INVOICENR = REPORT_SALES_100.INVOICENR
inner join PRODUCT_WITH_FAMILY using (ITEMNR)
inner join _C using (INVOICENR)
group by
ITEMNR,
PHYSICIAN,
BATCHID
order by
ITEMNR,
PHYSICIAN,
BATCHID;

what did I miss?

RobertOstermann commented 1 week ago

Does it do the same thing when you run it from the command line?

theking2 commented 1 week ago

Hmm. I can try if you tell me how to do that....

RobertOstermann commented 1 week ago

The Output channel should show you the exact command the extension uses to format the code. It might also tell you if there was an error formatting, which is probably why it is clearing out the code.

image

theking2 commented 1 week ago

Actually vscode and SQL don't seem to like each other. I've reinstalled sqlfluff but "MS SQL" seems to think the code is not valid at all. image

theking2 commented 1 week ago

image

theking2 commented 1 week ago

image

ok, I'm giving up