PabloRMira / sql_formatter

A Python based SQL formatter
https://pablormira.github.io/sql_formatter/
Apache License 2.0
43 stars 10 forks source link

case when wrongly formatted if case when at least in second argument and preceded by text in quotes #128

Closed PabloRMira closed 3 years ago

PabloRMira commented 3 years ago

To Reproduce

>>> from sql_formatter.core import format_sql
>>> print(format_sql("select asdf, substr('asdf', case when asdf = 1 then 1 else 0 end, 2) as qwerty from table1"))
SELECT asdf,
       substr('asdf', case when asdf = 1 then 1
               else 0 end, 2) as qwerty
FROM   table1

Expected behavior

SELECT asdf,
       substr('asdf', case when asdf = 1 then 1
                           else 0 end, 2) as qwerty
FROM   table1
PabloRMira commented 3 years ago

It is rather about the quotes, if we replace the text in quotes in the example above by a field, it works as expected