diff options
| -rw-r--r-- | CHANGES | 7 | ||||
| -rw-r--r-- | sqlparse/engine/grouping.py | 3 | ||||
| -rw-r--r-- | tests/test_regressions.py | 11 |
3 files changed, 21 insertions, 0 deletions
@@ -1,3 +1,10 @@ +Development Version +------------------- + +Bug Fixes +* Fix handling of NULL keywords in aliased identifiers. + + Release 0.1.11 (Feb 07, 2014) ----------------------------- diff --git a/sqlparse/engine/grouping.py b/sqlparse/engine/grouping.py index c11e5f0..bd97f41 100644 --- a/sqlparse/engine/grouping.py +++ b/sqlparse/engine/grouping.py @@ -117,6 +117,8 @@ def group_as(tlist): return not token.ttype in (T.DML, T.DDL) def _left_valid(token): + if token.ttype is T.Keyword and token.value in ('NULL'): + return True return token.ttype is not T.Keyword _group_left_right(tlist, T.Keyword, 'AS', sql.Identifier, @@ -233,6 +235,7 @@ def group_identifier_list(tlist): lambda t: t.ttype == T.Keyword, lambda t: isinstance(t, sql.Comparison), lambda t: isinstance(t, sql.Comment), + lambda t: t.ttype == T.Comment.Multiline, ] tcomma = tlist.token_next_match(idx, T.Punctuation, ',') start = None diff --git a/tests/test_regressions.py b/tests/test_regressions.py index 395c2b6..e30ddf0 100644 --- a/tests/test_regressions.py +++ b/tests/test_regressions.py @@ -233,3 +233,14 @@ def test_except_formatting(): 'WHERE 1 = 2' ]) assert formatted == tformatted + + +def test_null_with_as(): + sql = 'SELECT NULL AS c1, NULL AS c2 FROM t1' + formatted = sqlparse.format(sql, reindent=True) + tformatted = '\n'.join([ + 'SELECT NULL AS c1,', + ' NULL AS c2', + 'FROM t1' + ]) + assert formatted == tformatted
\ No newline at end of file |
