sqlfmt icon indicating copy to clipboard operation
sqlfmt copied to clipboard

UPDATE — update rows of a table for Postgres

Open MycrofD opened this issue 3 weeks ago • 0 comments

Describe the bug Unlike the main select statement which is not indented as its previous CTE, the main update seems to get aligned to its preceding CTE.

To Reproduce

with
    selected_campaign as (select c.* from from snp.campaigns as c2)

update snp.campaigns as c
set state = 'FORECAST_INITIATED'
from selected_campaign as sc
;

Actual behavior The above statement gets formatted to

with
    selected_campaign as (select c.* from from snp.campaigns as c2)

    update snp.campaigns as c
    set state = 'FORECAST_INITIATED'
from selected_campaign as sc
;

Expected behavior When the update statement is replaced with a select statement, it is formatted as:

with selected_campaign as (select c.* from from snp.campaigns as c2)

select *
from selected_campaign as sc
;

I would expect no indentation at the update statement

with
    selected_campaign as (select c.* from from snp.campaigns as c2)

update snp.campaigns as c -- no indentation here
set state = 'FORECAST_INITIATED'
from selected_campaign as sc
;

Even this is another confusion as to why the CTE is pushed to a newline for update but not for select. E.g. the following happens only for select

with selected_campaign as (select c.* from from snp.campaigns as c2)
...
;

But for update we have

with
    selected_campaign as (select c.* from from snp.campaigns as c2)
...
;

Additional context What is the output of sqlfmt --version? 0.26.0 in the pre-commit hook.

MycrofD avatar Dec 08 '25 17:12 MycrofD