tconbeer / sqlfmt

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

Formatting One of Snowflakes RLIKE Syntaxes Adds Superfluous Whitespace #478

Open chwiese opened 1 year ago

chwiese commented 1 year ago

Describe the bug Snowflakes RLIKE has two valid syntaxes. When formatting a Snowflake SQL script that uses the first syntax mentioned in the documentation, sqlfmt adds a whitespace between E and (.

To Reproduce Format the following: select rlike('foo', 'bar') from dual;

Expected behavior

select rlike('foo', 'bar')
from dual
;

Actual behavior

select rlike ('foo', 'bar')
from dual
;

Additional context sqlfmt, version 0.19.2

tconbeer commented 1 year ago

thanks for the report. Snowflake has similar syntax for like, ilike, etc., as functions instead of infix operators.

While this formatting isn't ideal, snowflake parses it and accepts it as valid.

A quick search of the other major dialects suggests this is snowflake-only.

tconbeer commented 1 year ago

I'm not going to tackle this right now -- because of how the lexer and parser work, it's non-trivial to distinguish between rlike('foo, bar') and rlike('foo', 'bar') when these tokens are lexed, which unfortunately determines the presence or absence of whitespace between the function or operator name and the parenthesis.