sqlfmt icon indicating copy to clipboard operation
sqlfmt copied to clipboard

integer division // operator reformatted as comment

Open manlon opened this issue 2 years ago • 2 comments

// 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 avatar Jan 13 '24 17:01 manlon

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

manlon avatar Jan 13 '24 17:01 manlon

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)

tconbeer avatar Jan 13 '24 18:01 tconbeer