sql-formatter-org / sql-formatter

A whitespace formatter for different query languages
https://sql-formatter-org.github.io/sql-formatter/
MIT License
2.3k stars 398 forks source link

"Prettier-SQL.tabulateAlias": true ignores back ticks #756

Closed theking2 closed 1 month ago

theking2 commented 1 month ago

Input data

Which SQL and options did you provide as input?

select
    coalesce(FAMILY_ITEMS_DESCRIPTION, 'nicht zugewiesen')  `Item family`,
    coalesce(SUBFAMILY_ITEMS_DESCRIPTION, 'nicht zugewiesen') `Item subfamily`,
    product.ITEMNR                                                  `Art-Nr.`,
    product.DESCRIPTION                                             Bezeichnung,
    coalesce(LOCATIONQTY, 0)                                        `Verfügbar`,
    STANDARDCOST                                                    EP,
    coalesce(StockAmount, 0)                                        `Lagerwert`,
    KONTONR
    /*, concat( KONTOBEZEICHNUNG, '|', KONTONR ) Account*/
from
    product
    left join product_family pf on ITEMFAMILY = FAMILY_ITEMS
    and ITEMSUBFAMILY = SUBFAMILY_ITEMS
    join (
        select
            ITEMNR,
            sum(LOCATIONQTY)                               LOCATIONQTY,
            sum(StockAmount)                               StockAmount,
            str_to_date(IP_TIMEDATEPK_REPORTING, '%Y%m%d') `last_date`,
            STANDARDCOST
        from
            report_stock_300
            join warehouse_300_state using (IP_WAREHOUSE, STOCKTYPE)
        where
            `State` = 'Verfügbar'
            and TDYEAR = $year
            and TDMONTH = $month
        group by
            ITEMNR,
            IP_TIMEDATEPK_REPORTING
    ) r300 using (ITEMNR)
order by
    coalesce(FAMILY_ITEMS, 'zz'),
    SUBFAMILY_ITEMS,
    product.DESCRIPTION

Expected Output

select 
    coalesce(FAMILY_ITEMS_DESCRIPTION, 'nicht zugewiesen')    `Item family`,
    coalesce(SUBFAMILY_ITEMS_DESCRIPTION, 'nicht zugewiesen') `Item subfamily`,
    product.ITEMNR                                            `Art-Nr.`,
    product.DESCRIPTION                                       Bezeichnung,
    coalesce(LOCATIONQTY, 0)                                  `Verfügbar`,
    STANDARDCOST                                              EP,
    coalesce(StockAmount, 0)                                  `Lagerwert`,
    KONTONR
    /*, concat( KONTOBEZEICHNUNG, '|', KONTONR ) Account*/
from
    product
    left join product_family pf on ITEMFAMILY = FAMILY_ITEMS
    and ITEMSUBFAMILY = SUBFAMILY_ITEMS
    join (
        select
            ITEMNR,
            sum(LOCATIONQTY)                               LOCATIONQTY,
            sum(StockAmount)                               StockAmount,
            str_to_date(IP_TIMEDATEPK_REPORTING, '%Y%m%d') `last_date`,
            STANDARDCOST
        from
            report_stock_300
            join warehouse_300_state using (IP_WAREHOUSE, STOCKTYPE)
        where
            `State` = 'Verfügbar'
            and TDYEAR = $year
            and TDMONTH = $month
        group by
            ITEMNR,
            IP_TIMEDATEPK_REPORTING
    ) r300 using (ITEMNR)
order by
    coalesce(FAMILY_ITEMS, 'zz'),
    SUBFAMILY_ITEMS,
    product.DESCRIPTION

Actual Output

select
    coalesce(FAMILY_ITEMS_DESCRIPTION, 'nicht zugewiesen') `Item    family`,
    coalesce(SUBFAMILY_ITEMS_DESCRIPTION, 'nicht zugewiesen') `Item subfamily`,
    product.ITEMNR                                                  `Art-Nr.`,
    product.DESCRIPTION                                             Bezeichnung,
    coalesce(LOCATIONQTY, 0)                                        `Verfügbar`,
    STANDARDCOST                                                    EP,
    coalesce(StockAmount, 0)                                        `Lagerwert`,
    KONTONR
    /*, concat( KONTOBEZEICHNUNG, '|', KONTONR ) Account*/
from
    product
    left join product_family pf on ITEMFAMILY = FAMILY_ITEMS
    and ITEMSUBFAMILY = SUBFAMILY_ITEMS
    join (
        select
            ITEMNR,
            sum(LOCATIONQTY)                               LOCATIONQTY,
            sum(StockAmount)                               StockAmount,
            str_to_date(IP_TIMEDATEPK_REPORTING, '%Y%m%d') `last_date`,
            STANDARDCOST
        from
            report_stock_300
            join warehouse_300_state using (IP_WAREHOUSE, STOCKTYPE)
        where
            `State` = 'Verfügbar'
            and TDYEAR = $year
            and TDMONTH = $month
        group by
            ITEMNR,
            IP_TIMEDATEPK_REPORTING
    ) r300 using (ITEMNR)
order by
    coalesce(FAMILY_ITEMS, 'zz'),
    SUBFAMILY_ITEMS,
    product.DESCRIPTION

Usage

nene commented 1 month ago

Prettier-SQL VSCode extension is outdated. Please read the FAQ.

However the tabulateAlias feature has been removed from SQL Formatter since 14.0.0 (because it was fundamentally broken, as demonstrated by the bug report above).