sqlfmt icon indicating copy to clipboard operation
sqlfmt copied to clipboard

Formatting One of Snowflakes RLIKE Syntaxes Adds Superfluous Whitespace

Open chwiese opened this issue 2 years ago • 2 comments

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

chwiese avatar Sep 05 '23 15:09 chwiese

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 avatar Sep 05 '23 16:09 tconbeer

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.

tconbeer avatar Sep 25 '23 18:09 tconbeer