sql-formatter-org / sql-formatter-org/sql-formatter
[FORMATTING] comments after final WITH statement
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 2.9k
- Forks
- 456
- Avg merge
- 3d 4h
- Merged PRs (30d)
- 3
Description
Input data
Which SQL and options did you provide as input?
/* fix late arriving client dimension keys */
with result as (
-- do the update
update star.fact_user fu
set dim_client_key = dim_client_hist.dim_client_key
from star.dim_client_hist
where
-- match business keys
fu.client_id = dim_client_hist.id
-- pick correct version
and fu.date between dim_client_hist.dss_start_date and dim_client_hist.dss_end_date
-- only update these records
and fu.dim_client_key = 0
and fu.client_id is not null
returning 1
)
, updated_rows as (
-- count the updated records
select count(*) as count
from result
)
-- return success message
select 1 as p_status
, (
'Updated ' || updated_rows.count || ' records from star.fact_user with late arriving dimensional keys from star.dim_client_hist'
)::varchar as p_return_msg
from updated_rows
;
Expected Output
I expected the comment in line 22 to be aligned with the select afte the comment
/* fix late arriving client dimension keys */
with result as (
-- do the update
update star.fact_user fu
set dim_client_key = dim_client_hist.dim_client_key
from star.dim_client_hist
where
-- match business keys
fu.client_id = dim_client_hist.id
-- pick correct version
and fu.date between dim_client_hist.dss_start_date and dim_client_hist.dss_end_date
-- only update these records
and fu.dim_client_key = 0
and fu.client_id is not null
returning 1
)
, updated_rows as (
-- count the updated records
select count(*) as count
from result
)
-- return success message
select 1 as p_status
, (
'Updated ' || updated_rows.count || ' records from star.fact_user with late arriving dimensional keys from star.dim_client_hist'
)::varchar as p_return_msg
from updated_rows
;
NB. Not sure if this will start to cause other problems if you manage to fix this
PS. the as statements (aliases) in line 23 & line 26 are also not aligned
Actual Output
/* fix late arriving client dimension keys */
with result as (
-- do the update
update star.fact_user fu
set dim_client_key = dim_client_hist.dim_client_key
from star.dim_client_hist
where
-- match business keys
fu.client_id = dim_client_hist.id
-- pick correct version
and fu.date between dim_client_hist.dss_start_date and dim_client_hist.dss_end_date
-- only update these records
and fu.dim_client_key = 0
and fu.client_id is not null
returning 1
)
, updated_rows as (
-- count the updated records
select count(*) as count
from result
)
-- return success message
select 1 as p_status
, (
'Updated ' || updated_rows.count || ' records from star.fact_user with late arriving dimensional keys from star.dim_client_hist'
)::varchar as p_return_msg
from updated_rows
Usage
- How are you calling / using the library?
-
What SQL language(s) does this apply to?
At least PostgreSQL -
Which SQL Formatter version are you using?
Online version
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the PostgreSQL example in the online formatter and compare the actual and expected placement of the comment after the final WITH clause, including the alias alignment noted in the report. Trace the SQL formatting entry point for this input and add or update a regression test; done means the formatted output matches the expected example without breaking related WITH-statement formatting.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- sql, typescript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100