tconbeer/sqlfmt

integer division // operator reformatted as comment

Opened this issue · 2 comments

manlon commented

// 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

I found the reason for this here #468 , but it's totally catastrophic when formatting duckdb queries with this op unfortunately

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)