tconbeer / sqlfmt

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

sqlfmt add space which is invalid #533

Closed aersam closed 7 months ago

aersam commented 7 months ago

Describe the bug A clear and concise description of what the bug is.

Sqlfmt turns this:

select regexp_replace(trim(ms.id), r'([^0-9])', '') as supplier_id

into this:

select regexp_replace(trim(ms.id), r '([^0-9])', '') as supplier_id

Note the space after the r Literal.

r Modifiers are a Spark/Databricks Feature: https://spark.apache.org/docs/latest/sql-ref-literals.html#string-literal They must be placed immediately before the actual string

Expected behavior The r Modifier before a string literal should not have any space to the string literal.

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

sqlfmt, version 0.21.0

That beeing said, we use sqlfmt for 885 SQL Files and that's the only bug we're having, big thanks for that great tool!

tconbeer commented 7 months ago

As with your other issue, I don't think my software is doing this. I can't reproduce this either locally or on sqlfmt.com. We test the double-quoted version of this here:

https://github.com/tconbeer/sqlfmt/blob/0e1e074686cc24e6ba8856dca12b3a37c2b48b06/tests/unit_tests/test_rule.py#L46

aersam commented 7 months ago

Very strange. I'm actually sure I'm on the right sqlfmt 🙂 I'll double check tomorrow