tconbeer / sqlfmt

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

integer division // operator reformatted as comment #548

Open manlon opened 8 months ago

manlon commented 8 months ago

// is an integer division operator in duckdb sql https://duckdb.org/docs/sql/functions/numeric.html sqlfmt interprets this as the start of a comment and reformats it to -- with invalid results.

$ echo 'select 5 // 2;' | sqlfmt  -
select 5  -- 2;

1 file formatted.
0 files left unchanged.
- formatted.

Expected behavior valid // operation passes through unchanged

Actual behavior // is changed to -- as above

Additional context What is the output of sqlfmt --version?

sqlfmt, version 0.21.1
manlon commented 8 months ago

I found the reason for this here https://github.com/tconbeer/sqlfmt/issues/468 , but it's totally catastrophic when formatting duckdb queries with this op unfortunately

tconbeer commented 8 months ago

Yeah, this is unfortunate. I checked as many dialects as I could and thought we were in the clear with //

Will have to be fixed with either a snowflake specific or duckdb specific dialect.

Workaround would be a --fmt: off comment on a PRECEDING line (same line won't work unfortunately)