tconbeer / sqlfmt

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

sqlfmt adds an extra space to PostgreSQL double tilda operators (`LIKE` alias) #576

Closed tuckerrc closed 2 months ago

tuckerrc commented 2 months ago

Describe the bug

PostgreSQL has a few aliases for the LIKE keyword (9.7.1. LIKE). sqlfmt adds a space between the ~~ operator, breaking the query.

Other operators specific to PostgreSQL (from the docs)

The operator ~~ is equivalent to LIKE, and ~~* corresponds to ILIKE. There are also !~~ and !~~* operators that represent NOT LIKE and NOT ILIKE, respectively. All of these operators are PostgreSQL-specific.

To Reproduce Steps to reproduce the behavior. If this is a formatting issue, include the input code here.

Input

with test as (select 'test' as test) select * from test where test ~~ 'test'

sqlfmt output

with test as (select 'test' as test) select * from test where test ~ ~ 'test'

Expected behavior

No spaces are added to the ~~ operator

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

$ sqlfmt --version
sqlfmt, version 0.21.2
tconbeer commented 2 months ago

Had no idea that was a thing. Thanks for the report!

tconbeer commented 2 months ago

@tuckerrc this has been patched in v0.21.3

tuckerrc commented 2 months ago

Thank you for the quick turnaround! I discovered it yesterday when sqlfmt broke a query in a large project. Now I don't need to change that query!