sqlparse icon indicating copy to clipboard operation
sqlparse copied to clipboard

Additional space when formatting with comma_first

Open wtn20 opened this issue 5 years ago • 0 comments

Small issue when formatting a comma first query, if there are spaces preceding the column identifier.

Example:

import sqlparse

sqlparse_format_options = {
            'keyword_case': 'lower',
            'identifier_case': 'lower',
            'strip_comments': True,
            'reindent_aligned': True,
            'use_space_around_operators': True,
            'comma_first': True,
        }


str_1 = '''
SELECT 
 *, foo.a
FROM foo WHERE bar
'''

formatted_1 = sqlparse.format(str_1, **sqlparse_format_options)

str_2 = '''
SELECT 
 *
 , foo.a
FROM foo WHERE bar
'''

formatted_2 = sqlparse.format(str_2, **sqlparse_format_options)

print(formatted_1 == formatted_2)
print()
print(formatted_1)
print()
print(formatted_2)

Returns

False

select *,
       foo.a
  from foo
 where bar

select * ,
       foo.a
  from foo
 where bar

Expected

True

select *,
       foo.a
  from foo
 where bar

select *,
       foo.a
  from foo
 where bar

wtn20 avatar Oct 05 '21 20:10 wtn20